package com.itlong.cloud.controller.current;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.type.TypeReference;
import com.itlong.cloud.POJO.DTO.app.*;
import com.itlong.cloud.POJO.DTO.common.PadFaceSyncDataDTO;
import com.itlong.cloud.POJO.PO.AppUserAccountBalancePO;
import com.itlong.cloud.POJO.PO.AppUserInfoPO;
import com.itlong.cloud.POJO.PO.ProjectPO;
import com.itlong.cloud.POJO.PO.UserLoginLogPO;
import com.itlong.cloud.POJO.VO.MessageVO;
import com.itlong.cloud.POJO.VO.app.*;
import com.itlong.cloud.POJO.VO.operate.OperateFaceApplyInfoVO;
import com.itlong.cloud.PlatformConstants;
import com.itlong.cloud.abstracts.BaseController;
import com.itlong.cloud.annotation.LoggerInfo;
import com.itlong.cloud.constants.LogDescConstant;
import com.itlong.cloud.constants.RedisConstant;
import com.itlong.cloud.enumerate.*;
import com.itlong.cloud.enumerate.ecode.AppErrorCodeEnum;
import com.itlong.cloud.enumerate.ecode.BaseErrorCodeEnum;
import com.itlong.cloud.enumerate.ecode.ErrorCode;
import com.itlong.cloud.enumerate.ecode_en.AppErrorCodeEnumEN;
import com.itlong.cloud.enumerate.ecode_en.BaseErrorCodeEnumEN;
import com.itlong.cloud.equip.app.IAppDevicePassRecordServiceClient;
import com.itlong.cloud.equip.app.IAppDeviceServiceClient;
import com.itlong.cloud.equip.app.IAppVisitorPassCodeRecordServiceClient;
import com.itlong.cloud.equip.property.IPadFaceSyncDataServiceClient;
import com.itlong.cloud.iottp.IIotBaiduFaceServiceClient;
import com.itlong.cloud.iottp.IIotVisitorFaceServiceClient;
import com.itlong.cloud.noncore.commons.IUserLoginLogServiceClient;
import com.itlong.cloud.paymenthub.IAccountBalanceServiceClient;
import com.itlong.cloud.project.app.IAppProjectServiceClient;
import com.itlong.cloud.project.app.IAppRoomServiceClient;
import com.itlong.cloud.project.operate.IOperateFaceApplyServiceClient;
import com.itlong.cloud.project.operate.IOperateProjectServiceClient;
import com.itlong.cloud.service.RedisService;
import com.itlong.cloud.thrown.DataAccessException;
import com.itlong.cloud.user.app.IAppMineServiceClient;
import com.itlong.cloud.user.app.IAppRegisterServiceClient;
import com.itlong.cloud.user.app.IAppUserInfoCacheServiceClient;
import com.itlong.cloud.user.property.IPropertyHouseHoldInfoServiceClient;
import com.itlong.cloud.user.property.IPropertyVisitorServiceClient;
import com.itlong.cloud.utils.date.DateUtil;
import com.itlong.cloud.utils.encrypt.Md5EncryptUtil;
import com.itlong.cloud.utils.encrypt.UserTokenUtil;
import com.itlong.cloud.utils.file.UploadFileUtil;
import com.itlong.cloud.utils.network.http.HttpProtocolUtil;
import com.itlong.cloud.utils.node.JsonUtil;
import com.itlong.cloud.utils.page.Page;
import com.itlong.cloud.utils.random.LogicIdUtil;
import com.itlong.cloud.utils.words.NumberHandlerUtil;
import com.itlong.cloud.utils.words.StringHandlerUtil;
import org.apache.commons.lang.StringUtils;
import org.apache.poi.util.StringUtil;
import org.slf4j.Logger;import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import sun.misc.BASE64Decoder;

import javax.servlet.http.HttpServletRequest;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.math.BigDecimal;
import java.net.URLDecoder;
import java.util.*;

/**
 * <desc>
 *     新版APP的我版块控制器
 * </desc>
 * @create  2017/9/19
 */
@RestController
@RequestMapping("/user")
@RefreshScope
public class AppMineController extends BaseController {
    private static final Logger LOG = LoggerFactory.getLogger(AppMineController.class);

    @Value("${" + PlatformConstants.APP_REQUEST_PARAMS_ENCRYPT_KEY + "}")
    public String APP_REQUEST_PARAMS_ENCRYPT_KEY;

    @Value("${" + PlatformConstants.APP_USER_TOKEN_KEY + "}")
    public String APP_USER_TOKEN_KEY;

    @Value("${" + PlatformConstants.FILE_FTP_HOST + "}")
    public String FILE_FTP_HOST;
    @Value("${" + PlatformConstants.FILE_FTP_PORT + "}")
    public String FILE_FTP_PORT;
    @Value("${" + PlatformConstants.FILE_FTP_USERNAME + "}")
    public String FILE_FTP_USERNAME;
    @Value("${" + PlatformConstants.FILE_FTP_PASSWORD + "}")
    public String FILE_FTP_PASSWORD;
    @Value("${" + PlatformConstants.FILE_ACCESS_URL + "}")
    public String FILE_ACCESS_URL;

    @Autowired
    IIotVisitorFaceServiceClient iIotVisitorFaceServiceClient;

    @Autowired
    IAppMineServiceClient iAppMineServiceClient;
    @Autowired
    RedisService<AppUserCacheVO> redisService;

    @Autowired
    IAppUserInfoCacheServiceClient userCache;

    @Autowired
    IAppRoomServiceClient iAppRoomServiceClient;

    @Autowired
    IAppDevicePassRecordServiceClient iAppDevicePassRecordServiceClient;

    //新版APP的项目信息接口
    @Autowired
    IAppProjectServiceClient iAppProjectServiceClient;

    //APP设备信息业务处理暴露接口
    @Autowired
    IAppDeviceServiceClient iAppDeviceServiceClient;

    //项目信息接口服务
    @Autowired
    IOperateProjectServiceClient iOperateProjectServiceClient;

    @Autowired
    IUserLoginLogServiceClient iUserLoginLogServiceClient;

    @Autowired
    IAppRegisterServiceClient iAppRegisterServiceClient;

    @Autowired
    IAccountBalanceServiceClient iAccountBalanceServiceClient;

    @Autowired
    IIotBaiduFaceServiceClient iIotBaiduFaceServiceClient;

    @Autowired
    IOperateFaceApplyServiceClient iOperateFaceApplyServiceClient;

    @Autowired
    IPadFaceSyncDataServiceClient iPadFaceSyncDataServiceClient;

    @Autowired
    IAppVisitorPassCodeRecordServiceClient iAppVisitorPassCodeRecordServiceClient;

    @Autowired
    IPropertyHouseHoldInfoServiceClient iPropertyHouseHoldInfoServiceClient;

    @Autowired
    IPropertyVisitorServiceClient iPropertyVisitorServiceClient;

    /**
     * <desc>
     *     APP端_我的，退出登录
     * </desc>
     * @param token
     * @return
     * @createDate 2017/10/10
     * @author cuiduanwu
     */
    @LoggerInfo(operateDesc = LogDescConstant.LOGIN_OUT)
    @RequestMapping(path = "/loginOut",method = RequestMethod.POST)
    @ResponseBody
    public Object loginOut(String token,String language,HttpServletRequest request){
        try {
            if (StringUtils.isBlank(token)) {
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            if (StringUtils.isBlank(token)){
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            String userId = UserTokenUtil.newAPPTokenDecrypt(token,APP_USER_TOKEN_KEY);
            AppUserCacheVO appUserCacheVO = redisService.getObject(RedisConstant.APP_LOGIN+userId,AppUserCacheVO.class);
            UserLoginLogPO userLoginLogPO = new UserLoginLogPO(appUserCacheVO.getPhoneNo(),appUserCacheVO.getUserName(), HttpProtocolUtil.getIpAddr(request));
            if ("1".equals(appUserCacheVO.getLoginDevice())){ //安卓
                userLoginLogPO.setSystemType(3);
            }else { //苹果
                userLoginLogPO.setSystemType(4);
            }
            boolean flag = iAppMineServiceClient.logOut(userId);
            if (flag){
                //LOG.info("【APP端_我的版块】登出清理缓存成功");
                userLoginLogPO.setDescription("登出"+BaseErrorCodeEnum.SUCCESS.getErrorCode().getCodeMsg());
                iUserLoginLogServiceClient.save(userLoginLogPO);
                ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.SUCCESS.getErrorCode():BaseErrorCodeEnumEN.SUCCESS.getErrorCode();
                return new MessageVO(errorCode);
            }else {
                //LOG.info("【APP端_我的版块】登出清理缓存失败");
                userLoginLogPO.setDescription("登出"+BaseErrorCodeEnum.ERROR.getErrorCode().getCodeMsg());
                iUserLoginLogServiceClient.save(userLoginLogPO);
                ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.ERROR.getErrorCode():BaseErrorCodeEnumEN.ERROR.getErrorCode();
                return new MessageVO(errorCode);
            }
        }catch (Exception e){
            throw new DataAccessException("【APP_我的_退出登录】退出登录失败",e);
        }
    }

    /**
     * <desc>
     *     APP端_我的,更新头像
     * </desc>
     * @param token
     * @param imageStr
     * @param imageType
     * @return photoUrl 头像地址
     * @createDate 2017/10/10
     * @author cuiduanwu
     */
    @LoggerInfo(operateDesc = LogDescConstant.APP_UPDATE_PHOTO)
    @RequestMapping(path = "/updatePhoto",method = RequestMethod.POST)
    @ResponseBody
    public Object updatePhoto(String token,String imageStr,String imageType,String createTime,String sign,String language){
        try {
            boolean flag = StringUtils.isNotBlank(createTime);
            if (!flag) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                imageStr = request.getAttribute("imageStr") == null ? null : request.getAttribute("imageStr").toString();
                imageType = request.getAttribute("imageType") == null ? null : request.getAttribute("imageType").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            //验签
            Map<String,String> params = new HashMap<>();
            params.put("imageType",imageType);
            params.put("createTime",createTime);
            params.put("language",language);
            if (flag) {
                params.put("imageStr",imageStr);
                if (!Md5EncryptUtil.checkAppSign(params, sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode():AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return  new MessageVO(errorCode);
                }
            } else {
                if (!Md5EncryptUtil.checkAppSignValue(params, sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode():AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return  new MessageVO(errorCode);
                }
            }
            if (StringUtils.isBlank(imageStr)||StringUtils.isBlank(imageType)||StringUtils.isBlank(createTime)){
                ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.NOT_PARAM.getErrorCode(): BaseErrorCodeEnumEN.NOT_PARAM.getErrorCode();
                return new MessageVO(errorCode);
            }
            String userId = UserTokenUtil.newAPPTokenDecrypt(token,APP_USER_TOKEN_KEY);
            String photoUrl = iAppMineServiceClient.updatePhoto(userId, imageStr, imageType);
            JSONObject js = new JSONObject();
            if (StringUtils.isBlank(photoUrl)){
                photoUrl = "";
            }
            js.put("photoUrl",photoUrl);
            ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.SUCCESS.getErrorCode(): BaseErrorCodeEnumEN.SUCCESS.getErrorCode();
            return  new MessageVO(errorCode,js);
        }catch (Exception e){
            throw new DataAccessException("【APP_我的版块_更新头像】更新头像失败",e);
        }
    }

    /**
     * <desc>
     *     APP端_我的,更新昵称
     * </desc>
     * @param token
     * @param nickName
     * @return
     * @createDate 2017/10/10
     * @author cuiduanwu
     */
    @LoggerInfo(operateDesc = LogDescConstant.APP_UPDATE_NICKNAME)
    @RequestMapping(path = "/updateNickName",method = RequestMethod.POST)
    @ResponseBody
    public Object updateNickName(String token,String nickName,String createTime,String sign,String language){
        try {
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                nickName = request.getAttribute("nickName") == null ? null : request.getAttribute("nickName").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            //验签
            Map<String,String> params = new HashMap<>();
            params.put("nickName",nickName);
            params.put("createTime",createTime);
            params.put("language",language);
            if (flag1) {
                if (!Md5EncryptUtil.checkAppSign(params, sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode():AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return  new MessageVO(errorCode);
                }
            } else {
                if (!Md5EncryptUtil.checkAppSignValue(params, sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode():AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return  new MessageVO(errorCode);
                }
            }
            if (StringUtils.isBlank(nickName)||StringUtils.isBlank(createTime)){
                ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.NOT_PARAM.getErrorCode():BaseErrorCodeEnumEN.NOT_PARAM.getErrorCode();
                return  new MessageVO(errorCode);
            }

            String userId = UserTokenUtil.newAPPTokenDecrypt(token,APP_USER_TOKEN_KEY);
            boolean flag = iAppMineServiceClient.updateNickName(userId,nickName);
            if (flag){
                ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.SUCCESS.getErrorCode():BaseErrorCodeEnumEN.SUCCESS.getErrorCode();
                return  new MessageVO(errorCode);
            }else {
                ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.ERROR.getErrorCode():BaseErrorCodeEnumEN.ERROR.getErrorCode();
                return  new MessageVO(errorCode);
            }
        }catch (Exception e){
            throw new DataAccessException("【APP_我的版块_更新昵称】更新昵称失败",e);
        }

    }
    /**
     * <desc>
     *     APP端_我的,更新密码
     * </desc>
     * @param token
     * @param oldPswd
     * @param currentPswd
     * @return
     * @createDate 2017/10/10
     * @author cuiduanwu
     */
    @LoggerInfo(operateDesc = LogDescConstant.APP_UPDATE_PSWD)
    @RequestMapping(path = "/updatePswd",method = RequestMethod.POST)
    @ResponseBody
    public Object updatePswd(String token,String oldPswd,String currentPswd,String createTime,String sign,String language){
        try {
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                oldPswd = request.getAttribute("oldPswd") == null ? null : request.getAttribute("oldPswd").toString();
                currentPswd = request.getAttribute("currentPswd") == null ? null : request.getAttribute("currentPswd").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            //验签
            Map<String,String> params = new HashMap<>();
            params.put("oldPswd",oldPswd);
            params.put("currentPswd",currentPswd);
            params.put("createTime",createTime);
            params.put("language",language);
            if (flag1) {
                if (!Md5EncryptUtil.checkAppSign(params, sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode():AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return  new MessageVO(errorCode);
                }
            } else {
                if (!Md5EncryptUtil.checkAppSignValue(params, sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode():AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return  new MessageVO(errorCode);
                }
            }
            String oldPwd = oldPswd;
            oldPswd = UserTokenUtil.getPassword(oldPswd, APP_USER_TOKEN_KEY);
            //如果解密失败不做处理，此try catch主要做兼容旧版本app用户密码与后台交互并没有做des加密
            if(oldPswd == null) {
                oldPswd = oldPwd;
            }
            String currentPwd = currentPswd;
            currentPswd = UserTokenUtil.getPassword(currentPswd, APP_USER_TOKEN_KEY);
            //如果解密失败不做处理，此try catch主要做兼容旧版本app用户密码与后台交互并没有做des加密
            if(currentPswd == null) {
                currentPswd = currentPwd;
            }
            if (StringUtils.isBlank(oldPswd)||StringUtils.isBlank(currentPswd)||StringUtils.isBlank(createTime)){
                ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.NOT_PARAM.getErrorCode():AppErrorCodeEnumEN.NOT_PARAM.getErrorCode();
                return  new MessageVO(errorCode);
            }else if (oldPswd.length()<6||oldPswd.length()>16||currentPswd.length()<6||currentPswd.length()>16){
                ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.PSWD_LENGTH_ERROR.getErrorCode():AppErrorCodeEnumEN.PSWD_LENGTH_ERROR.getErrorCode();
                return new MessageVO(errorCode);
            }
            String userId = UserTokenUtil.newAPPTokenDecrypt(token,APP_USER_TOKEN_KEY);
            boolean flag = iAppMineServiceClient.updatePswd(userId, Md5EncryptUtil.md5(oldPswd), Md5EncryptUtil.md5(currentPswd));
            if (flag){
                ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.SUCCESS.getErrorCode():BaseErrorCodeEnumEN.SUCCESS.getErrorCode();
                return  new MessageVO(errorCode);
            }else {
                LOG.info("【APP_我的版块_更新密码失败】");
                ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.OLD_PSWD_ERROR.getErrorCode():AppErrorCodeEnumEN.OLD_PSWD_ERROR.getErrorCode();
                return  new MessageVO(errorCode);
            }
        }catch (Exception e){
            throw new DataAccessException("【APP_我的版块_更新密码】更新密码失败",e);
        }

    }
    /**
     * <desc>
     *     APP端_我的,更新性别
     * </desc>
     * @param token
     * @param sex 性别：0女、1男
     * @return
     * @createDate 2017/10/10
     * @author cuiduanwu
     */
    @LoggerInfo(operateDesc = LogDescConstant.APP_UPDATE_USERSEX)
    @RequestMapping(path = "/updateUserSex",method = RequestMethod.POST)
    @ResponseBody
    public Object updateSex(String token,String sex,String createTime,String sign,String language){
        try {
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                sex = request.getAttribute("sex") == null ? null : request.getAttribute("sex").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            //验签
            Map<String,String> params = new HashMap<>();
            params.put("sex",sex);
            params.put("createTime",createTime);
            params.put("language",language);
            if (flag1) {
                if (!Md5EncryptUtil.checkAppSign(params, sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode():AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return  new MessageVO(errorCode);
                }else if (StringUtils.isBlank(sex)||StringUtils.isBlank(createTime)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.NOT_PARAM.getErrorCode():BaseErrorCodeEnumEN.NOT_PARAM.getErrorCode();
                    return  new MessageVO(errorCode);
                }else if (!("0".equals(sex.trim())||"1".equals(sex.trim()))){
                    LOG.info("【APP_我的版块_性别参数异常】sex:"+sex);
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.PARAM_ERR.getErrorCode():BaseErrorCodeEnumEN.PARAM_ERR.getErrorCode();
                    return  new MessageVO(errorCode);
                }
            } else {
                if (!Md5EncryptUtil.checkAppSignValue(params, sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode():AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return  new MessageVO(errorCode);
                }else if (StringUtils.isBlank(sex)||StringUtils.isBlank(createTime)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.NOT_PARAM.getErrorCode():BaseErrorCodeEnumEN.NOT_PARAM.getErrorCode();
                    return  new MessageVO(errorCode);
                }else if (!("0".equals(sex.trim())||"1".equals(sex.trim()))){
                    LOG.info("【APP_我的版块_性别参数异常】sex:"+sex);
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.PARAM_ERR.getErrorCode():BaseErrorCodeEnumEN.PARAM_ERR.getErrorCode();
                    return  new MessageVO(errorCode);
                }
            }

            String userId = UserTokenUtil.newAPPTokenDecrypt(token,APP_USER_TOKEN_KEY);
            boolean flag = iAppMineServiceClient.updateSex(userId, sex);
            if (flag){
                ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.SUCCESS.getErrorCode():BaseErrorCodeEnumEN.SUCCESS.getErrorCode();
                return  new MessageVO(errorCode);
            }else {
                ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.ERROR.getErrorCode():BaseErrorCodeEnumEN.ERROR.getErrorCode();
                return  new MessageVO(errorCode);
            }
        }catch (Exception e){
            throw new DataAccessException("【APP_我的版块_更新性别】更新性别失败",e);
        }
    }

    /**
     * <desc>
     *     APP端_我的,意见反馈
     * </desc>
     * @param token
     * @param projectId
     * @param feedbackInfo
     * @return
     * @createDate 2017/10/10
     * @author cuiduanwu
     */
    @RequestMapping(path = "/feedBack/add",method = RequestMethod.POST)
    @ResponseBody
    @LoggerInfo(operateDesc = LogDescConstant.APP_ADD_FEED_BACK_LOG)
    public Object addFeedBack(String token,String projectId,String feedbackInfo,String createTime,String sign,String language,
                              String problemType, String appVersion, String androidVersion, String phoneModel,
                              String contactInformation, String imageAry, String netType, String systemName){
        try {
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                projectId = request.getAttribute("projectId") == null ? null : request.getAttribute("projectId").toString();
                feedbackInfo = request.getAttribute("feedbackInfo") == null ? null : request.getAttribute("feedbackInfo").toString();
                problemType = request.getAttribute("problemType") == null ? null : request.getAttribute("problemType").toString();
                appVersion = request.getAttribute("appVersion") == null ? null : request.getAttribute("appVersion").toString();
                androidVersion = request.getAttribute("androidVersion") == null ? null : request.getAttribute("androidVersion").toString();
                phoneModel = request.getAttribute("phoneModel") == null ? null : request.getAttribute("phoneModel").toString();
                contactInformation = request.getAttribute("contactInformation") == null ? null : request.getAttribute("contactInformation").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
                imageAry = request.getAttribute("imageAry") == null ? null : request.getAttribute("imageAry").toString();
                netType = request.getAttribute("netType") == null ? null : request.getAttribute("netType").toString();
                systemName = request.getAttribute("systemName") == null ? null : request.getAttribute("systemName").toString();
            }
            //验签
            Map<String,String> params = new HashMap<>();
            params.put("projectId",projectId);
            params.put("feedbackInfo",feedbackInfo);
            params.put("problemType",problemType);
            params.put("appVersion",appVersion);
            params.put("androidVersion",androidVersion);
            params.put("phoneModel",phoneModel);
            params.put("contactInformation",contactInformation);
            params.put("createTime",createTime);
            params.put("language",language);
            params.put("imageAry", imageAry);
            params.put("netType", netType);
            params.put("systemName", systemName);
            if (flag1) {
                if (!Md5EncryptUtil.checkAppSign(params, sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode():AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return  new MessageVO(errorCode);
                }else if (StringUtils.isBlank(feedbackInfo)||StringUtils.isBlank(createTime) || StringUtils.isBlank(netType) || StringUtils.isBlank(systemName)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.NOT_PARAM.getErrorCode():BaseErrorCodeEnumEN.NOT_PARAM.getErrorCode();
                    return  new MessageVO(errorCode);
                }else if (feedbackInfo.length()>300){
                    LOG.info("【APP_我的版块_意见反馈内容过长】");
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.FEEDBACK_TOO_LONG.getErrorCode():AppErrorCodeEnumEN.FEEDBACK_TOO_LONG.getErrorCode();
                    return  new MessageVO(errorCode);
                }else if (StringUtils.isNotBlank(projectId)&&!projectId.matches("[0-9]{8}")){
                    LOG.info("【APP_我的版块_意见反馈_项目编号非法】"+projectId);
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.PROJECT_NOT_MATCH.getErrorCode():AppErrorCodeEnumEN.PROJECT_NOT_MATCH.getErrorCode();
                    return  new MessageVO(errorCode);
                }
            } else {
                if (!Md5EncryptUtil.checkAppSignValue(params, sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode():AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return  new MessageVO(errorCode);
                }else if (StringUtils.isBlank(feedbackInfo)||StringUtils.isBlank(createTime)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.NOT_PARAM.getErrorCode():BaseErrorCodeEnumEN.NOT_PARAM.getErrorCode();
                    return  new MessageVO(errorCode);
                }else if (feedbackInfo.length()>300){
                    LOG.info("【APP_我的版块_意见反馈内容过长】");
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.FEEDBACK_TOO_LONG.getErrorCode():AppErrorCodeEnumEN.FEEDBACK_TOO_LONG.getErrorCode();
                    return  new MessageVO(errorCode);
                }else if (StringUtils.isNotBlank(projectId)&&!projectId.matches("[0-9]{8}")){
                    LOG.info("【APP_我的版块_意见反馈_项目编号非法】"+projectId);
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.PROJECT_NOT_MATCH.getErrorCode():AppErrorCodeEnumEN.PROJECT_NOT_MATCH.getErrorCode();
                    return  new MessageVO(errorCode);
                }
            }
            if (StringUtils.isBlank(projectId)){
                projectId = "";
            }

            String userId = UserTokenUtil.newAPPTokenDecrypt(token,APP_USER_TOKEN_KEY);
            StringBuilder imageUrlStr = new StringBuilder();
            if(StringUtils.isNotBlank(imageAry)){
                List<AppServiceUploadRepairImgDTO> appImageDTOList = JSONArray.parseArray(imageAry, AppServiceUploadRepairImgDTO.class);
                if (appImageDTOList!= null && !appImageDTOList.isEmpty()){
                    for (AppServiceUploadRepairImgDTO appImageDTO : appImageDTOList){
                        String imageUrl = this.uploadImageFile(appImageDTO.getImageUrl(), appImageDTO.getImageType(), FileCatalogEnum.FEEDBACK_FILE);
                        if(imageUrlStr.length() == 0){
                            imageUrlStr.append(imageUrl);
                        }else {
                            imageUrlStr.append(",").append(imageUrl);
                        }
                    }
                }
            }
            boolean result = iAppMineServiceClient.addFeedBackInfo(userId, projectId, feedbackInfo, problemType, appVersion, androidVersion, phoneModel, contactInformation,imageUrlStr.toString(), netType, systemName);
            ErrorCode errorCode = null;
            if (result){
                errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.SUCCESS.getErrorCode():BaseErrorCodeEnumEN.SUCCESS.getErrorCode();
            }else {
                errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.ERROR.getErrorCode():BaseErrorCodeEnumEN.ERROR.getErrorCode();
            }
            return  new MessageVO(errorCode);
        }catch (Exception e){
            throw new DataAccessException("【APP_我的版块_意见反馈】意见反馈失败",e);
        }
    }

    /**
     * <desc>
     *      所在对应小区有权限的楼栋等信息
     * </desc>
     *
     * @param token 用户token
     * @param projectId 项目id
     * @param createTime 时间戳 验证签名
     * @param owner 是否只查业主 1是 0否
     * @param sign  签名
     * @return
     * @author Jiaqi.x
     * @createDate 2017/10/27
     */
    @RequestMapping(path = "/authPerson/ownerUserInfo",method = RequestMethod.POST)
    @ResponseBody
    public Object ownerUserInfo(String token,String projectId,String createTime,String owner,String sign,String language){
        MessageVO messageVO;
        try{
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                projectId = request.getAttribute("projectId") == null ? null : request.getAttribute("projectId").toString();
                owner = request.getAttribute("owner") == null ? null : request.getAttribute("owner").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            Map<String,String> params = new HashMap<>();
            params.put("projectId",projectId);
            params.put("createTime",createTime);
            params.put("owner",owner);
            params.put("language",language);
           //验证签名
            if (flag1) {
                if(!Md5EncryptUtil.checkAppSign(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode():AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return  new MessageVO(errorCode);
                }else if (StringUtils.isBlank(projectId)||StringUtils.isBlank(createTime)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.NOT_PARAM.getErrorCode():BaseErrorCodeEnumEN.NOT_PARAM.getErrorCode();
                    return  new MessageVO(errorCode);
                }else if (!projectId.matches("[0-9]{8}")){
                    LOG.info("【APP_我的版块_查询有权楼栋信息_项目编号非法】"+projectId);
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.PROJECT_NOT_MATCH.getErrorCode():AppErrorCodeEnumEN.PROJECT_NOT_MATCH.getErrorCode();
                    return  new MessageVO(errorCode);
                }
            } else {
                if(!Md5EncryptUtil.checkAppSignValue(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode():AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return  new MessageVO(errorCode);
                }else if (StringUtils.isBlank(projectId)||StringUtils.isBlank(createTime)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.NOT_PARAM.getErrorCode():BaseErrorCodeEnumEN.NOT_PARAM.getErrorCode();
                    return  new MessageVO(errorCode);
                }else if (!projectId.matches("[0-9]{8}")){
                    LOG.info("【APP_我的版块_查询有权楼栋信息_项目编号非法】"+projectId);
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.PROJECT_NOT_MATCH.getErrorCode():AppErrorCodeEnumEN.PROJECT_NOT_MATCH.getErrorCode();
                    return  new MessageVO(errorCode);
                }
            }
            //从缓存中获取用户信息
            AppUserCacheVO userInfo=userCache.retrieve(token);
            List<AppRoomAuthVO> list=iAppRoomServiceClient.getUseRoomsByUserIdAndProjectId(userInfo.getUserId(),projectId,owner);
            list.forEach(vo->{
                vo=(AppRoomAuthVO) StringHandlerUtil.formatString(vo);
            });
            Map<String,Object> map=new HashMap<>();
            map.put("roomArr",list);
            ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.SUCCESS.getErrorCode():BaseErrorCodeEnumEN.SUCCESS.getErrorCode();
            messageVO = new MessageVO(errorCode,map);
        }catch (Exception e){
            throw new DataAccessException("【APP_我的版块】获取所在对应小区有权限的楼栋等信息失败ownerUserInfo",e);
        }
        return messageVO;
    }

    /**
     * <desc>
     *      获取用户有通行记录的日期分页列表
     * </desc>
     *
     * @param dto 接收数据dto类
     * @param sign 签名
     * @return
     * @author Jiaqi.X
     * @createDate 2017/11/09
     */
    @RequestMapping(path = "/deviceRecord/datelist",method = RequestMethod.POST)
    @ResponseBody
    public Object getVisitorRecord(AppGetDateListPageDTO dto,String sign){
        MessageVO messageVO;
        try {
            boolean flag1 = StringUtils.isNotBlank(sign);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                dto = HttpProtocolUtil.parseRequestParamToDTO(AppGetDateListPageDTO.class, request);
            }
            //验证签名
            if (flag1) {
                if(!Md5EncryptUtil.checkAppSign(dto,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(dto.getLanguage())?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode():AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return  new MessageVO(errorCode);
                }
            } else {
                if(!Md5EncryptUtil.checkAppSignValue(dto,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(dto.getLanguage())?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode():AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return  new MessageVO(errorCode);
                }
            }
            if (StringUtils.isBlank(dto.getProjectId()) || !dto.getProjectId().matches("[0-9]{8}")){
                LOG.info("【APP_首页版块】获取用户有通行记录的日期分页列表_项目编号非法】"+dto.getProjectId());
                ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(dto.getLanguage())?AppErrorCodeEnum.PROJECT_NOT_MATCH.getErrorCode():AppErrorCodeEnumEN.PROJECT_NOT_MATCH.getErrorCode();
                return  new MessageVO(errorCode);
            }
            //从缓存中获取用户信息
            AppUserCacheVO userInfo=userCache.retrieve(dto.getToken());
            dto.setLoginUserId(userInfo.getUserId());
            //查询
            Page<String> page=iAppDevicePassRecordServiceClient.getPassDateListPage(dto);
            Map<String,Object> map=new HashMap<>();
            page.getRows().forEach(row->{
                if(StringUtils.isBlank(row)){
                    row="";
                }
            });
            //判断是否是国内，如果是国内不对时间做处理，否则处理时间格式
            if(!dto.getLanguage().equals(LanguageTypeEnum.CHINESE.getLanguage())){
                for(int i=page.getRows().size() - 1 ; i >= 0 ; i--){
                    System.out.println(DateUtil.fomatDate(DateUtil.formatStringToDate(page.getRows().get(i),DateUtil.YMDN),DateUtil.DATE_FORMAT_TYPE4));
                    page.getRows().set(i,DateUtil.fomatDate(DateUtil.formatStringToDate(page.getRows().get(i),DateUtil.YMDN),DateUtil.DATE_FORMAT_TYPE4));
                }
            }
            map.put("date",page.getRows());
            map.put("pageCount",page.getPage().getTotalPage());
            ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(dto.getLanguage())?BaseErrorCodeEnum.SUCCESS.getErrorCode():BaseErrorCodeEnumEN.SUCCESS.getErrorCode();
            messageVO=new MessageVO(errorCode,map);
        }catch (Exception e){
            throw new DataAccessException("【APP_我的版块】获取用户有通行记录的日期分页列表失败",e);
        }
        return messageVO;
    }

    /**
     * <desc>
     *      获取用户通行记录列表
     * </desc>
     *
     * @param dto 接收数据dto类
     * @param sign 签名
     * @return
     * @author Jiaqi.X
     * @createDate 2017/11/09
     */
    @RequestMapping(path = "/deviceRecord/dateRecordlist",method = RequestMethod.POST)
    @ResponseBody
    public Object dateRecordlist(AppGetPassRecordListPageDTO dto,String sign){
        MessageVO messageVO;
        try {
            boolean flag1 = StringUtils.isNotBlank(sign);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                dto = HttpProtocolUtil.parseRequestParamToDTO(AppGetPassRecordListPageDTO.class, request);
            }
            //验证签名
            if (flag1) {
                if(!Md5EncryptUtil.checkAppSign(dto,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(dto.getLanguage())?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode():AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return  new MessageVO(errorCode);
                }
            } else {
                if(!Md5EncryptUtil.checkAppSignValue(dto,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(dto.getLanguage())?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode():AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return  new MessageVO(errorCode);
                }
            }
            if (StringUtils.isBlank(dto.getProjectId()) || !dto.getProjectId().matches("[0-9]{8}")){
                LOG.info("【APP_我的版块】获取用户通行记录列表_项目编号非法】"+dto.getProjectId());
                ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(dto.getLanguage())?AppErrorCodeEnum.PROJECT_NOT_MATCH.getErrorCode():AppErrorCodeEnumEN.PROJECT_NOT_MATCH.getErrorCode();
                return  new MessageVO(errorCode);
            }
            //从缓存中获取用户信息
            AppUserCacheVO userInfo=userCache.retrieve(dto.getToken());
            dto.setLoginUserId(userInfo.getUserId());
            //判断是否是国内，如果是国内不对时间做处理，否则处理时间格式
            if(!dto.getLanguage().equals(LanguageTypeEnum.CHINESE.getLanguage())){
                dto.setDate(DateUtil.fomatDate(DateUtil.formatStringToDate(dto.getDate(),DateUtil.DATE_FORMAT_TYPE4),DateUtil.YMDN));
            }
            //查询
            Page<AppGetPassRecordListPageVO> page=iAppDevicePassRecordServiceClient.getPage(dto);
//            page.getRows().forEach(row->{
//                row=(AppGetPassRecordListPageVO)StringHandlerUtil.formatString(row);
//            });
            Map<String,Object> map=new HashMap<>();
            map.put("recordlist",page.getRows());
            map.put("pageCount",page.getPage().getTotalPage());
            ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(dto.getLanguage())?BaseErrorCodeEnum.SUCCESS.getErrorCode():BaseErrorCodeEnumEN.SUCCESS.getErrorCode();
            messageVO=new MessageVO(errorCode,map);
        }catch (Exception e){
            throw new DataAccessException("【APP_我的版块】获取用户通行记录列表失败",e);
        }
        return messageVO;
    }

    /**
     * <desc>
     *      获取通行记录列表，app2.0版本新增
     * </desc>
     *
     * @return 标准格式化响应结果
     * @author wangzhi
     * @createDate 2019/06/18
     */
    @ResponseBody
    @PostMapping("getOpenDoorRecord")
    public Object getOpenDoorRecord(String projectId, String pageIndex, String token, String createTime, String sign, String language){
        try {
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                projectId = request.getAttribute("projectId") == null ? null : request.getAttribute("projectId").toString();
                pageIndex = request.getAttribute("pageIndex") == null ? null : request.getAttribute("pageIndex").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            //验签
            Map<String, String> params = new HashMap<>();
            params.put("projectId", projectId);
            params.put("pageIndex", pageIndex);
            params.put("createTime", createTime);
            params.put("language", language);
            if (flag1) {
                if (!Md5EncryptUtil.checkAppSign(params, sign, APP_REQUEST_PARAMS_ENCRYPT_KEY)) {
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language) ? AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode() : AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }
            } else {
                if (!Md5EncryptUtil.checkAppSignValue(params, sign, APP_REQUEST_PARAMS_ENCRYPT_KEY)) {
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language) ? AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode() : AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }
            }

            if (StringUtils.isBlank(projectId) || StringUtils.isBlank(pageIndex) || StringUtils.isBlank(token)) {
                return new MessageVO(LanguageTypeEnum.CHINESE.getLanguage().equals(language) ? BaseErrorCodeEnum.NOT_PARAM.getErrorCode() : BaseErrorCodeEnumEN.NOT_PARAM.getErrorCode());
            }
            // 从缓存中获取用户信息
            AppUserCacheVO userInfo = (AppUserCacheVO) StringHandlerUtil.formatString(userCache.retrieve(token));
            Map<String, Object> data = iAppDevicePassRecordServiceClient.getOpenDoorRecord(projectId, pageIndex, userInfo.getUserId());
            ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language) ? BaseErrorCodeEnum.SUCCESS.getErrorCode() : BaseErrorCodeEnumEN.SUCCESS.getErrorCode();
            return new MessageVO(errorCode, data);
        } catch (Exception e) {
            throw new DataAccessException("【APP_我的版块】（2.0）获取通行记录列表失败", e);
        }
    }

    /**
     * <desc>
     *      获取访客通行密码邀请记录
     * </desc>
     *
     * @return 标准格式化响应结果
     * @author wangzhi
     * @createDate 2019/06/24
     */
    @ResponseBody
    @PostMapping("getInvateRecord")
    public Object getInviteRecord(String projectId, String token, String pageNo, String pageSize, String createTime, String sign, String language){
        try {
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                projectId = request.getAttribute("projectId") == null ? null : request.getAttribute("projectId").toString();
                pageNo = request.getAttribute("pageNo") == null ? null : request.getAttribute("pageNo").toString();
                pageSize = request.getAttribute("pageSize") == null ? null : request.getAttribute("pageSize").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            //验签
            Map<String, String> params = new HashMap<>();
            params.put("projectId", projectId);
            params.put("pageNo", pageNo);
            params.put("pageSize", pageSize);
            params.put("createTime", createTime);
            params.put("language", language);
            if (flag1) {
                if (!Md5EncryptUtil.checkAppSign(params, sign, APP_REQUEST_PARAMS_ENCRYPT_KEY)) {
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language) ? AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode() : AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }
            } else {
                if (!Md5EncryptUtil.checkAppSignValue(params, sign, APP_REQUEST_PARAMS_ENCRYPT_KEY)) {
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language) ? AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode() : AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }
            }

            if (StringUtils.isBlank(projectId) || StringUtils.isBlank(pageNo) || StringUtils.isBlank(token) || StringUtils.isBlank(pageSize)) {
                return new MessageVO(LanguageTypeEnum.CHINESE.getLanguage().equals(language) ? BaseErrorCodeEnum.NOT_PARAM.getErrorCode() : BaseErrorCodeEnumEN.NOT_PARAM.getErrorCode());
            }
            // 从缓存中获取用户信息
            AppUserCacheVO userInfo = (AppUserCacheVO) StringHandlerUtil.formatString(userCache.retrieve(token));
            Map<String, Object> data = iAppDevicePassRecordServiceClient.getInviteRecord(projectId, pageNo, pageSize, userInfo.getUserId());
            ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language) ? BaseErrorCodeEnum.SUCCESS.getErrorCode() : BaseErrorCodeEnumEN.SUCCESS.getErrorCode();
            return new MessageVO(errorCode, data);
        } catch (Exception e) {
            throw new DataAccessException("【APP_我的版块】获取访客通行密码邀请记录失败", e);
        }
    }

    /**
     * <desc>
     *      获取有效的访客通行密码记录
     * </desc>
     *
     * @return 标准格式化响应结果
     * @author wangzhi
     * @createDate 2019/07/11
     */
    @ResponseBody
    @PostMapping("getValueInvitLog")
    public Object getValueInviteLog(String projectId, String token, String pageNo, String pageSize, String createTime, String sign, String language){
        try {
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                projectId = request.getAttribute("projectId") == null ? null : request.getAttribute("projectId").toString();
                pageNo = request.getAttribute("pageNo") == null ? null : request.getAttribute("pageNo").toString();
                pageSize = request.getAttribute("pageSize") == null ? null : request.getAttribute("pageSize").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            //验签
            Map<String, String> params = new HashMap<>();
            params.put("projectId", projectId);
            params.put("pageNo", pageNo);
            params.put("pageSize", pageSize);
            params.put("createTime", createTime);
            params.put("language", language);
            if (flag1) {
                if (!Md5EncryptUtil.checkAppSign(params, sign, APP_REQUEST_PARAMS_ENCRYPT_KEY)) {
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language) ? AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode() : AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }
            } else {
                if (!Md5EncryptUtil.checkAppSignValue(params, sign, APP_REQUEST_PARAMS_ENCRYPT_KEY)) {
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language) ? AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode() : AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }
            }

            if (StringUtils.isBlank(projectId) || StringUtils.isBlank(pageNo) || StringUtils.isBlank(token) || StringUtils.isBlank(pageSize)) {
                return new MessageVO(LanguageTypeEnum.CHINESE.getLanguage().equals(language) ? BaseErrorCodeEnum.NOT_PARAM.getErrorCode() : BaseErrorCodeEnumEN.NOT_PARAM.getErrorCode());
            }
            // 从缓存中获取用户信息
            AppUserCacheVO userInfo = (AppUserCacheVO) StringHandlerUtil.formatString(userCache.retrieve(token));
            Map<String, Object> data = iAppVisitorPassCodeRecordServiceClient.getAvailableVisitorPwd(projectId, pageNo, pageSize, userInfo.getUserId());
            ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language) ? BaseErrorCodeEnum.SUCCESS.getErrorCode() : BaseErrorCodeEnumEN.SUCCESS.getErrorCode();
            return new MessageVO(errorCode, data);
        } catch (Exception e) {
            throw new DataAccessException("【APP_我的版块】获取有效的访客通行密码记录失败", e);
        }
    }

    /**
     * <desc>
     *      获取乘梯记录
     * <desc/>
     *
     * @return
     * @author Qiang.S
     * @createDate 2019-06-26
     */
    @RequestMapping(value = "/getLiftHistory",method = RequestMethod.POST)
    @ResponseBody
    public Object getLiftHistory(String pageNum, String token, String language, String createTime, String sign) {
        MessageVO messageVO;
        try {
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                pageNum = request.getAttribute("pageNum") == null ? null : request.getAttribute("pageNum").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            //验签
            Map<String,String> params = new HashMap<>();
            params.put("pageNum", pageNum);
            params.put("createTime",createTime);
            params.put("language",language);
            //验证签名
            if (flag1) {
                if (!Md5EncryptUtil.checkAppSign(params, sign, APP_REQUEST_PARAMS_ENCRYPT_KEY)) {
                    return new MessageVO(AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode());
                }
            } else {
                if (!Md5EncryptUtil.checkAppSignValue(params, sign, APP_REQUEST_PARAMS_ENCRYPT_KEY)) {
                    return new MessageVO(AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode());
                }
            }
            if (StringUtils.isBlank(pageNum) || StringUtils.isBlank(token)) {
                return new MessageVO(LanguageTypeEnum.CHINESE.getLanguage().equals(language) ? BaseErrorCodeEnum.NOT_PARAM.getErrorCode() : BaseErrorCodeEnumEN.NOT_PARAM.getErrorCode());
            }
            //从缓存中获取用户信息
            AppUserCacheVO userInfo=userCache.retrieve(token);
            Map<String, Object> data = iAppDevicePassRecordServiceClient.getLiftHistory(pageNum,userInfo.getUserId());
            messageVO = new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),data);
            return messageVO;
        } catch (Exception e) {
            throw new DataAccessException("【APP_我的版块】获取乘梯记录异常", e);
        }
    }

    /**
     * <desc>
     *      上传通行记录
     * </desc>
     *
     * @param token 用户token
     * @param recordJson json字符串
     * @param createTime 时间戳 验证签名
     * @param sign 签名
     * @return
     * @author Jiaqi.X
     * @createDate 2017/11/10
     */
    @RequestMapping(path = "/deviceRecord/upload",method = RequestMethod.POST)
    @ResponseBody
    public Object dateRecordlist(String token,String projectId1,String recordJson,String createTime,String sign,String language,String imageStr,String imageType){
        MessageVO messageVO;
        try {
            boolean flag1 = StringUtils.isNotBlank(createTime);
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            projectId1 = request.getParameter("projectId");
            if (!flag1) {
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                projectId1 = request.getAttribute("projectId") == null ? null : request.getAttribute("projectId").toString();
                recordJson = request.getAttribute("recordJson") == null ? null : request.getAttribute("recordJson").toString();
                imageStr = request.getAttribute("imageStr") == null ? null : request.getAttribute("imageStr").toString();
                imageType = request.getAttribute("imageType") == null ? null : request.getAttribute("imageType").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            String projectId = projectId1;
            Map<String,String> params = new HashMap<>();
            params.put("createTime",createTime);
            params.put("projectId",projectId);
            params.put("language",language);
            //验证签名
            if (flag1) {
                params.put("recordJson",recordJson);
                if(!Md5EncryptUtil.checkAppSign(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode():AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return  new MessageVO(errorCode);
                }
            } else {
                if(!Md5EncryptUtil.checkAppSignValue(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode():AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return  new MessageVO(errorCode);
                }
            }
            if(StringUtils.isEmpty(imageStr) && StringUtils.isEmpty(imageType)){
                imageStr="";
                imageType="";
            }
            recordJson = URLDecoder.decode(recordJson, "UTF-8");
            List<AppUploadRecordJsonDTO> dtos= JsonUtil.decode(recordJson, new TypeReference<List<AppUploadRecordJsonDTO>>(){});
            if(dtos==null || dtos.size()>=100){
                ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.SUCCESS.getErrorCode():BaseErrorCodeEnumEN.SUCCESS.getErrorCode();
                return new MessageVO(errorCode);
            }

            //从缓存中获取用户信息
            AppUserCacheVO userInfo=userCache.retrieve(token);
            final String recordStr = recordJson;
            final String imageTemp = imageStr;
            final String imgTemp = imageType;
            Thread thread = new Thread(new Runnable() {
                @Override
                public void run() {
                    try {
                        List < AppUploadPassErrorVO > list = iAppDevicePassRecordServiceClient.uploadRecord(userInfo.getUserId(), projectId, recordStr, imageTemp, imgTemp);
                    } catch (Exception e) {

                    }
                }
            }
            );
            thread.start();
//            if(list.isEmpty() || null ==list) {
            ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.SUCCESS.getErrorCode():BaseErrorCodeEnumEN.SUCCESS.getErrorCode();
            messageVO = new MessageVO(errorCode);
//            }else{
//                Map<String,Object> result=new HashMap<>();
//                list.forEach(vo->{
//                    vo=(AppUploadPassErrorVO)StringHandlerUtil.formatString(vo);
//                });
//                result.put("failrecordlist",list);
//                ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.ERROR.getErrorCode():BaseErrorCodeEnumEN.ERROR.getErrorCode();
//                messageVO=new MessageVO(errorCode,result);
//            }
        }catch (Exception e){
            throw new DataAccessException("【APP_我的版块】上传用户通行记录失败",e);
        }
        return messageVO;
    }

    /**
     * <desc>
     *      设置开门密码
     * </desc>
     *
     * @param token 用户token
     * @param projectId 项目id
     * @param doorPwd 开门密码
     * @param sign 签名
     * @param loginPwd 登录密码
     * @return
     * @author Jiaqi.X
     * @createDate 2017/11/13
     */
    @LoggerInfo(operateDesc = LogDescConstant.APP_SET_OPEN_PWD)
    @RequestMapping(path = "/setDoorPwd",method = RequestMethod.POST)
    @ResponseBody
    public Object setDoorPwd(String token,String projectId,String doorPwd,String createTime,String sign,String language,String loginPwd){
        MessageVO messageVO;
        try {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            String encryptScript = request.getParameter("ciphertext");
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                projectId = request.getAttribute("projectId") == null ? null : request.getAttribute("projectId").toString();
                doorPwd = request.getAttribute("doorPwd") == null ? null : request.getAttribute("doorPwd").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
                loginPwd = request.getAttribute("loginPwd") == null ? null : request.getAttribute("loginPwd").toString();
            }
            Map<String,String> params = new HashMap<>();
            params.put("projectId",projectId);
            params.put("doorPwd",doorPwd);
            params.put("createTime",createTime);
            params.put("language",language);
            //此处判断为兼容新旧版本问题
            if (!StringUtils.isBlank(encryptScript)) {
                params.put("loginPwd",loginPwd);
            }
            //验证签名
            if (flag1) {
                if(!Md5EncryptUtil.checkAppSign(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode():AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return  new MessageVO(errorCode);
                }
            } else {
                if(!Md5EncryptUtil.checkAppSignValue(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode():AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return  new MessageVO(errorCode);
                }
            }
            boolean a = StringHandlerUtil.isSameChars(doorPwd);
            boolean b = StringHandlerUtil.isContinuousNumber(doorPwd);
            if (StringUtils.isBlank(projectId) || !projectId.matches("[0-9]{8}")){
                LOG.info("【APP_我的版块】获取用户通行记录列表_项目编号非法】"+projectId);
                ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.PROJECT_NOT_MATCH.getErrorCode():AppErrorCodeEnumEN.PROJECT_NOT_MATCH.getErrorCode();
                return  new MessageVO(errorCode);
            }else if (StringUtils.isBlank(doorPwd)){
                ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.OPEN_PASSWORD_IS_NULL.getErrorCode():AppErrorCodeEnumEN.OPEN_PASSWORD_IS_NULL.getErrorCode();
                return new MessageVO(errorCode);
            }else if(!doorPwd.matches("[0-9]{4}")){
                ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.OPEN_PASSWORD_IS_ERROR.getErrorCode():AppErrorCodeEnumEN.OPEN_PASSWORD_IS_ERROR.getErrorCode();
                return new MessageVO(errorCode);
            }else if(!StringHandlerUtil.isSameChars(doorPwd) || !StringHandlerUtil.isContinuousNumber(doorPwd)){
                ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.OPEN_PASSWORD_IS_WEAK_PASSWORD.getErrorCode():AppErrorCodeEnumEN.OPEN_PASSWORD_IS_ERROR.getErrorCode();
                return new MessageVO(errorCode);
            }
            //从缓存中获取用户信息
            AppUserCacheVO userInfo=userCache.retrieve(token);
            //检查用户是否是业主
            if(iAppRegisterServiceClient.countUserAttacheInfoInProject(userInfo.getUserId(),projectId) < 1){
                ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.USER_NOT_OWNER.getErrorCode():AppErrorCodeEnumEN.USER_NOT_OWNER.getErrorCode();
                return new MessageVO(errorCode);
            }
            //修改密码前需校验登录密码是否正确
            if(StringUtils.isNotEmpty(loginPwd)){
                loginPwd = UserTokenUtil.getPassword(loginPwd, APP_USER_TOKEN_KEY);
                if(iAppRegisterServiceClient.checkLoginPwd(userInfo.getUserId(),Md5EncryptUtil.md5(loginPwd))==0){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.LOGIN_PASSWORD_IS_ERROR.getErrorCode():AppErrorCodeEnumEN.LOGIN_PASSWORD_IS_ERROR.getErrorCode();
                    return new MessageVO(errorCode);
                }
            }
            iAppRoomServiceClient.setOpenPwd(projectId,userInfo.getUserId(),doorPwd);
            //推送设备拉取业主信息
            iAppDeviceServiceClient.pushCloudDeviceAuth(projectId,userInfo.getUserId(),
                    SmartCommunityEnum.PUSH_ROOM.getCommandType());
            ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.SUCCESS.getErrorCode():BaseErrorCodeEnumEN.SUCCESS.getErrorCode();
            messageVO=new MessageVO(errorCode);
        }catch (Exception e){
            throw new DataAccessException("【APP_我的版块】设置开门密码失败",e);
        }
        return messageVO;
    }

    /**
     * <desc>
     *      设置App是否允许被呼叫
     * </desc>
     *
     * @param token 用户token
     * @param isAllowApp 是否允许被呼叫
     * @param sign 签名
     * @return
     * @author Jiaqi.X
     * @createDate 2017/11/13
     */
    @LoggerInfo(operateDesc = LogDescConstant.APP_SET_ALLOW_APP)
    @RequestMapping(path = "/setAllowApp",method = RequestMethod.POST)
    @ResponseBody
    public Object setAllowApp(String token,String isAllowApp,String createTime,String sign,String language){
        MessageVO messageVO;
        try {
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                isAllowApp = request.getAttribute("isAllowApp") == null ? null : request.getAttribute("isAllowApp").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            Map<String,String> params = new HashMap<>();
            params.put("isAllowApp",isAllowApp);
            params.put("createTime",createTime);
            params.put("language",language);
            //验证签名
            if (flag1) {
                if(!Md5EncryptUtil.checkAppSign(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)) {
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode():AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }
            } else {
                if(!Md5EncryptUtil.checkAppSignValue(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)) {
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode():AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }
            }
            //从缓存中获取用户信息
            AppUserCacheVO userInfo=userCache.retrieve(token);
            iAppProjectServiceClient.setAllowApp(userInfo.getUserId(), Integer.valueOf(isAllowApp),null);
            //推送设备拉取业主信息
            iAppDeviceServiceClient.pushCloudDeviceAuth(null,userInfo.getUserId(),
                    SmartCommunityEnum.PUSH_USER_PROJECT.getCommandType());
            ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.SUCCESS.getErrorCode():BaseErrorCodeEnumEN.SUCCESS.getErrorCode();
            messageVO=new MessageVO(errorCode);
        }catch (Exception e){
            throw new DataAccessException("【APP_我的版块】设置App是否允许被呼叫失败",e);
        }
        return messageVO;
    }

    /**
     * <desc>
     *      设置电话是否允许被呼叫
     * </desc>
     *
     * @param token 用户token
     * @param projectId 项目id
     * @param isAllowPhone 开门密码
     * @param sign 签名
     * @return
     * @author Jiaqi.X
     * @createDate 2017/11/13
     */
    @LoggerInfo(operateDesc = LogDescConstant.APP_SET_ALLOW_PHONE)
    @RequestMapping(path = "/setAllowPhone",method = RequestMethod.POST)
    @ResponseBody
    public Object setAllowPhone(String token,String projectId,String isAllowPhone,String createTime,String sign,String language){
        MessageVO messageVO;
        try {
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                projectId = request.getAttribute("projectId") == null ? null : request.getAttribute("projectId").toString();
                isAllowPhone = request.getAttribute("isAllowPhone") == null ? null : request.getAttribute("isAllowPhone").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            Map<String,String> params = new HashMap<>();
            params.put("projectId",projectId);
            params.put("isAllowPhone",isAllowPhone);
            params.put("createTime",createTime);
            params.put("language",language);
            //验证签名
            if (flag1) {
                if(!Md5EncryptUtil.checkAppSign(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode():AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }
            } else {
                if(!Md5EncryptUtil.checkAppSignValue(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode():AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }
            }
            if (StringUtils.isBlank(projectId) || !projectId.matches("[0-9]{8}")) {
                LOG.info("【APP_我的版块】设置电话是否允许被呼叫_项目编号非法】" + projectId);
                ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.PROJECT_NOT_MATCH.getErrorCode():AppErrorCodeEnumEN.PROJECT_NOT_MATCH.getErrorCode();
                return  new MessageVO(errorCode);
            }
            //从缓存中获取用户信息
            AppUserCacheVO userInfo=userCache.retrieve(token);
            iAppProjectServiceClient.setAllowPhone(projectId, userInfo.getUserId(),isAllowPhone);
            //推送设备拉取业主信息
            iAppDeviceServiceClient.pushCloudDeviceAuth(projectId,userInfo.getUserId(),
                    SmartCommunityEnum.PUSH_ROOM.getCommandType());
            ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.SUCCESS.getErrorCode():BaseErrorCodeEnumEN.SUCCESS.getErrorCode();
            messageVO=new MessageVO(errorCode);
        }catch (Exception e){
            throw new DataAccessException("【APP_我的版块】设置电话是否允许被呼叫失败",e);
        }
        return messageVO;
    }

    /**
      * <desc>
      *      获取授权人列表。
      * <desc/>
      *
      * @param  pageDTO 授权人获取列表请求参数
      * @return
      * @author shengen.T
      * @createDate 2017/11/10
      */
    @RequestMapping(path = "/authPerson/list",method = RequestMethod.POST)
    @ResponseBody
    public Object getAuthPersonList(AppGetAuthPersonPageDTO pageDTO,String sign){
        MessageVO messageVO;
        try {
            boolean flag1 = StringUtils.isNotBlank(sign);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                pageDTO = HttpProtocolUtil.parseRequestParamToDTO(AppGetAuthPersonPageDTO.class, request);
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
            }
            //验证签名
            if (flag1) {
                if(!Md5EncryptUtil.checkAppSign(pageDTO,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    return  new MessageVO(AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode());
                }
            } else {
                if(!Md5EncryptUtil.checkAppSignValue(pageDTO,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    return  new MessageVO(AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode());
                }
            }
            //判断项目编号
            if(StringUtils.isBlank(pageDTO.getProjectId()) || !pageDTO.getProjectId().matches("[0-9]{8}")){
                LOG.info("【APP_我的版块】获取授权人列表_项目编号非法】" + pageDTO.getProjectId());
                return new MessageVO(AppErrorCodeEnum.PROJECT_NOT_MATCH.getErrorCode());
            }
            //从缓存中获取用户信息
            AppUserCacheVO userInfo=userCache.retrieve(pageDTO.getToken());
            if(null == userInfo){
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            long startTime = System.currentTimeMillis(); //程序开始记录时间

            //获取当前项目的状态 0 冻结 1启用
            Integer userProjectStatus = iAppMineServiceClient.getAppUserProjectStatus(userInfo.getUserId(),pageDTO.getProjectId());
            //冻结
            if(AppUserProjectStatusEnum.USERPROJECT_USERPROJECTSTATUS_FROZEN.getType()==userProjectStatus){
                String errInfo = String.format(AppErrorCodeEnum.USER_PROJECT_FREEZE_NOT_AUTH.getCodeMsg(),userInfo.getCurrentProjectName());
                return new MessageVO(AppErrorCodeEnum.USER_PROJECT_FREEZE_NOT_AUTH.getErrorCode(),errInfo);
            }
            pageDTO.setLoginUserId(userInfo.getUserId());
            Page<AppMineGetAuthPersonPageVO> authPersonPageVOPage =iAppMineServiceClient.getAuthPersonPage(pageDTO);
            long endTime  = System.currentTimeMillis(); //程序结束记录时间
            long TotalTime = endTime- startTime;       //总消耗时间
            System.out.print(String.format("查询耗时：%s毫秒\t\n",TotalTime));
            if((authPersonPageVOPage.getRows()!=null)&&(authPersonPageVOPage.getRows().size()>0)){
                for(AppMineGetAuthPersonPageVO itemVO:authPersonPageVOPage.getRows()){
                    StringHandlerUtil.formatString(itemVO);
                }
            }
            Map<String,Object> map=new HashMap<>();
            map.put("authorizer",authPersonPageVOPage.getRows());
            map.put("pageCount",authPersonPageVOPage.getPage().getTotalPage());
            messageVO = new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),map);
        }catch (Exception e){
            throw new DataAccessException("【APP_我的版块】获取授权人列表失败",e);
        }
        return messageVO;
    }


     /**
      * <desc>
      *      获取家人房间信息。
      * <desc/>
      *
      * @param  pageDTO
      * @return
      * @author shengen.T
      * @createDate 2018-01-23
      */
    @RequestMapping(path = "/authPersonRoom",method = RequestMethod.POST)
    @ResponseBody
    public Object getAuthPersonRoomInfo(AppAuthPersonGetRoomInfoDTO pageDTO,String sign){
       MessageVO messageVO;
       try {
           boolean flag1 = StringUtils.isNotBlank(sign);
           if (!flag1) {
               HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
               pageDTO = HttpProtocolUtil.parseRequestParamToDTO(AppAuthPersonGetRoomInfoDTO.class, request);
               sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
           }
           long startTime = System.currentTimeMillis(); //程序开始记录时间
           //验证签名
           if (flag1) {
               if(!Md5EncryptUtil.checkAppSign(pageDTO,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                   return  new MessageVO(AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode());
               }
           } else {
               if(!Md5EncryptUtil.checkAppSignValue(pageDTO,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                   return  new MessageVO(AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode());
               }
           }
           //判断项目编号
           if(StringUtils.isBlank(pageDTO.getProjectId()) || !pageDTO.getProjectId().matches("[0-9]{8}")){
               LOG.info("【APP_我的版块】获取授权人列表_项目编号非法】" + pageDTO.getProjectId());
               return new MessageVO(AppErrorCodeEnum.PROJECT_NOT_MATCH.getErrorCode());
           }
           //判断被授权手机号
           if(!NumberHandlerUtil.isPhoneNo(pageDTO.getAuthPhoneNo())){
               return new MessageVO(AppErrorCodeEnum.VISIT_PHONE_IS_ERROR.getErrorCode());
           }
           //从缓存中获取用户信息
           AppUserCacheVO userInfo=userCache.retrieve(pageDTO.getToken());
           if(null == userInfo){
               return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
           }

           pageDTO.setLoginUserId(userInfo.getUserId());
           List<AppMineGetAddressInfoVO> addressInfoList = iAppMineServiceClient.getAuthPersonRoomInfo(pageDTO);
          if((addressInfoList!=null)&&(addressInfoList.size()>0)){
              for(AppMineGetAddressInfoVO addressInfoVO:addressInfoList){
                  StringHandlerUtil.formatString(addressInfoVO);
              }
          }

           Map<String,Object> map=new HashMap<>();
           map.put("addressInfo",addressInfoList);
           messageVO = new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),map);
           long endTime  = System.currentTimeMillis(); //程序结束记录时间
           long TotalTime = endTime- startTime;       //总消耗时间
           System.out.print(String.format("查询耗时：%s毫秒\t\n",TotalTime));

       }catch (Exception e){
           throw new DataAccessException("【APP_我的版块】获取授权人房间信息失败",e);
       }
       return messageVO;
    }


    /**
     * <desc>
     *      添加授权人。
     * <desc/>
     *
     * @param  saveDTO 添加授权人请求参数
     * @param  sign 签名参数
     * @return
     * @author shengen.T
     * @createDate 2017/11/13
     */
    @LoggerInfo(operateDesc = LogDescConstant.APP_ADD_AUTHPERSON_INFO)
    @RequestMapping(path = "/authPerson/add",method = RequestMethod.POST)
    @ResponseBody
    public Object addAuthPerson(AppMineSaveAuthPersonDTO saveDTO, String sign){
        MessageVO messageVO;
        try {
            boolean flag1 = StringUtils.isNotBlank(sign);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                saveDTO = HttpProtocolUtil.parseRequestParamToDTO(AppMineSaveAuthPersonDTO.class, request);
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
            }
            //验证签名
            if (flag1) {
                if(!Md5EncryptUtil.checkAppSign(saveDTO,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    return  new MessageVO(AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode());
                }
            } else {
                if(!Md5EncryptUtil.checkAppSignValue(saveDTO,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    return  new MessageVO(AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode());
                }
            }
            //判断项目编号
            if(StringUtils.isBlank(saveDTO.getProjectId()) || !saveDTO.getProjectId().matches("[0-9]{8}")){
                LOG.info("【APP_我的版块】添加授权人_项目编号非法】" + saveDTO.getProjectId());
                return new MessageVO(AppErrorCodeEnum.PROJECT_NOT_MATCH.getErrorCode());
            }
            //判断被授权人的手机号
            if(!NumberHandlerUtil.isPhoneNo(saveDTO.getAuthPhoneNo())){
                return new MessageVO(AppErrorCodeEnum.PHONE_NOT_MATCH.getErrorCode());
            }
            //判断授权房间号
            if(StringUtils.isBlank(saveDTO.getRoomNums())){
                return new MessageVO(AppErrorCodeEnum.ROOM_NUMBER_EMPTY_ERR.getErrorCode());
            }
            //判断操作类型
            if((!"1".equals(saveDTO.getType()))&&(!"2".equals(saveDTO.getType()))){
                 return new MessageVO(AppErrorCodeEnum.OPERATE_TYPE_ERROR.getErrorCode());
            }
            //从缓存中获取用户信息
            AppUserCacheVO userInfo=userCache.retrieve(saveDTO.getToken());
            if(null == userInfo){
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            long startTime = System.currentTimeMillis(); //程序开始记录时间
            //获取当前项目的状态 0 冻结 1启用
            Integer userProjectStatus = iAppMineServiceClient.getAppUserProjectStatus(userInfo.getUserId(),saveDTO.getProjectId());
            //冻结
            if(AppUserProjectStatusEnum.USERPROJECT_USERPROJECTSTATUS_FROZEN.getType()==userProjectStatus){
               String errInfo = String.format(AppErrorCodeEnum.USER_PROJECT_FREEZE_NOT_AUTH.getCodeMsg(),userInfo.getCurrentProjectName());
                return new MessageVO(AppErrorCodeEnum.USER_PROJECT_FREEZE_NOT_AUTH.getErrorCode(),errInfo);
            }
            //判断是否使用云对讲  0-否，1-是
            Integer  isSmartCommunity= iOperateProjectServiceClient.getIsSmartCommunity(saveDTO.getProjectId());
            if(isSmartCommunity==null){
                LOG.info("【APP_我的版块】添加授权人_项目编号非法】" + saveDTO.getProjectId());
                return new MessageVO(AppErrorCodeEnum.PROJECT_NOT_MATCH.getErrorCode());
            }
            //判断该业主是否存在该房间权限 #当前小区信息不存在
           // List<AppRoomAuthVO> list=iAppRoomServiceClient.getUseRoomsByUserIdAndProjectId(userInfo.getUserId(),saveDTO.getProjectId(),"1");
            List<String> roomList = iAppMineServiceClient.getOwnerRoomIdLists(userInfo.getUserId(),saveDTO.getProjectId());
            if((roomList!=null)&&(roomList.size()>0)){
//                List<String> roomList = new ArrayList<>();
//                for (AppRoomAuthVO authVO:list){
//                    roomList.add(authVO.getRoomNum());
//                }
                String roomId[] =  StringHandlerUtil.splitString(saveDTO.getRoomNums());
                if(!roomList.containsAll(Arrays.asList(roomId))){
                    return new MessageVO(AppErrorCodeEnum.EXIT_INVALID_ROOMINFO_ERROR.getErrorCode());
                }
            }else {
                return new MessageVO(AppErrorCodeEnum.NOT_ADDAUTH_ROOMINFO_ERROR.getErrorCode());
            }
            String roomIdArr[] =  StringHandlerUtil.splitString(saveDTO.getRoomNums());
            //被授权的用户信息

            AppUserInfoPO authUserInfo = iAppMineServiceClient.getUserInfoByPhoneNo(saveDTO.getAuthPhoneNo());
            String userId="";
            if(authUserInfo!=null){
                userId = authUserInfo.getUserId();
            }
            for (int i=0;i<roomIdArr.length;i++){
                //已经授权的数目
                userId = StringUtils.isNotBlank(userId)?userId:"";
                //获取该房屋类型 1住宅 2办公
                Integer housesType = iPropertyHouseHoldInfoServiceClient.getHousesType(roomIdArr[i], saveDTO.getProjectId());
                Integer alreadyAuthNum = iAppMineServiceClient.getUserRoomCount(userId,saveDTO.getProjectId(),roomIdArr[i]);
                //查询当前项目信息
                ProjectPO projectPO = iOperateProjectServiceClient.getOneProject(saveDTO.getProjectId());
                //一个房间最大邀请人数是包括业主在内的人数
                Integer maxAuthNum = projectPO.getAuthMaxNum();
                Integer officeMaxAuthNum = projectPO.getOfficeAuthMaxNum();
                if(officeMaxAuthNum==0){
                    officeMaxAuthNum=11;
                }
                if(maxAuthNum==0){
                    return new MessageVO(AppErrorCodeEnum.NOT_ADD_OPENAUTH_ERROR.getErrorCode());
                }
                if(housesType==1 && alreadyAuthNum>=maxAuthNum){
                    String roomName = iAppMineServiceClient.getRoomName(saveDTO.getProjectId(),roomIdArr[i]);
                    //住宅房间入住人数已满
                    String errInfo = String.format(AppErrorCodeEnum.ROOM_NUM_MAX_ERROR.getCodeMsg(),roomName);
                    return new MessageVO(AppErrorCodeEnum.ROOM_NUM_MAX_ERROR.getErrorCode(),errInfo);
                }
                if(housesType==3 && alreadyAuthNum>=officeMaxAuthNum){
                    String roomName = iAppMineServiceClient.getRoomName(saveDTO.getProjectId(),roomIdArr[i]);
                    //办公房间入住人数已满
                    String errInfo = String.format(AppErrorCodeEnum.ROOM_NUM_MAX_ERROR.getCodeMsg(),roomName);
                    return new MessageVO(AppErrorCodeEnum.ROOM_NUM_MAX_ERROR.getErrorCode(),errInfo);
                }
            }
            //判断授权用户是否是业主自己
            if(userInfo.getUserId().equals(userId)){
                return new MessageVO(AppErrorCodeEnum.ADD_AUTHPERSON_SELF_ERROR.getErrorCode());
            }
            if("1".equals(saveDTO.getType())){
                Integer countUserId = iAppMineServiceClient.getUserAuthRelationCount(userInfo.getUserId(),userId,saveDTO.getProjectId());
                if(countUserId>0){
                    //存在该用户，不能重新添加房间信息
                    if(StringUtils.isNotEmpty(saveDTO.getUserRemarks())){
                        return new MessageVO(AppErrorCodeEnum.ADD_AUTHPERSON_EXIT_ERROR.getErrorCode());
                    }
                }
            }
            AppMineAuthPersonExtendDTO extendDTO = new AppMineAuthPersonExtendDTO(userId,saveDTO.getProjectId(),saveDTO.getAuthPhoneNo(),saveDTO.getUserRemarks(),saveDTO.getRoomNums(),isSmartCommunity);
            extendDTO.setLoginUserId(userInfo.getUserId());
//            extendDTO.setHouserType(saveDTO.getHouserType());
            //检测是否是新用户
            if (StringUtils.isBlank(userId)&&(authUserInfo==null)){
                AppUserInfoPO appUserInfoPO = new AppUserInfoPO();
                appUserInfoPO.setUserId(LogicIdUtil.userBusinessId());
                String phoneNo = saveDTO.getAuthPhoneNo();
                String nickName = String.format("%s%s","U_",phoneNo.substring(phoneNo.length()-4,phoneNo.length())
                );
                appUserInfoPO.setNickName(nickName);
                appUserInfoPO.setPhoneNum(phoneNo);
                appUserInfoPO.setToken(UserTokenUtil.tokenEncrypt(
                        appUserInfoPO.getUserId(),APP_USER_TOKEN_KEY, SystemTypeEnum.IOS.getType()));
                appUserInfoPO.setStatus(1);
                appUserInfoPO.setCreateTime(new Date());
                //新用户
                extendDTO.setUserId(appUserInfoPO.getUserId());
                extendDTO.setAppUserInfoPO(appUserInfoPO);
            }else {  //用户状态
                extendDTO.setStatus(authUserInfo.getStatus());
            }
            //添加用户信息
            Map<String, Object> resultMap= iAppMineServiceClient.addAuthPerson(extendDTO);
            long endTime  = System.currentTimeMillis(); //程序结束记录时间
            long TotalTime = endTime- startTime;       //总消耗时间
            System.out.print(String.format("查询耗时：%s毫秒\t\n",TotalTime));
            AppGetAuthPersonPageDTO pageDTO = new AppGetAuthPersonPageDTO();
            pageDTO.setPageNo("1");
            pageDTO.setPageSize("15");
            pageDTO.setLoginUserId(userInfo.getUserId());
            pageDTO.setProjectId(saveDTO.getProjectId());
            if(!"true".equals(resultMap.get("returnCode").toString())){
                return  new MessageVO(BaseErrorCodeEnum.ERROR.getErrorCode(),resultMap.get("hintInfo").toString());
            }
            Thread.sleep(500);//为了主从数据同步问题，延迟500毫秒查询
            Page<AppMineGetAuthPersonPageVO> PageVOPage =iAppMineServiceClient.getAuthPersonPage(pageDTO);
            if(PageVOPage.getRows()!=null){
                for(AppMineGetAuthPersonPageVO itemVO:PageVOPage.getRows()){
                    StringHandlerUtil.formatString(itemVO);
                }
            }
            Map<String,Object> map=new HashMap<>();
            System.out.print(JSON.toJSONString(PageVOPage.getRows()));
            map.put("authorizer",PageVOPage.getRows());
            messageVO = new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),map);
        }catch (Exception e){
            throw new DataAccessException("【APP_我的版块】添加授权人失败",e);
        }
        return messageVO;
    }

     /**
      * <desc>
      *      删除授权人。
      * <desc/>
      *
      * @param  authPhoneNo 被授权的手机号
      * @return
      * @author shengen.T
      * @createDate 2017/11/15
      */
    @LoggerInfo(operateDesc = LogDescConstant.APP_DEL_AUTHPERSON_INFO)
    @RequestMapping(path = "/authPerson/delete",method = RequestMethod.POST)
    @ResponseBody
    public Object deleteAuthPerson(String token,String authPhoneNo,String createTime,String sign,String language){
        MessageVO messageVO;
        try {
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                authPhoneNo = request.getAttribute("authPhoneNo") == null ? null : request.getAttribute("authPhoneNo").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            Map<String,String> params = new HashMap<>();
            params.put("authPhoneNo",authPhoneNo);
            params.put("createTime",createTime);
            params.put("language",language);
            //验证签名
            if (flag1) {
                if(!Md5EncryptUtil.checkAppSign(params, sign, APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    return  new MessageVO(AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode());
                }
            } else {
                if(!Md5EncryptUtil.checkAppSignValue(params, sign, APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    return  new MessageVO(AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode());
                }
            }
            //判断被授权人的手机号
            if(!NumberHandlerUtil.isPhoneNo(authPhoneNo)){
                return new MessageVO(AppErrorCodeEnum.PHONE_NOT_MATCH.getErrorCode());
            }
            //从缓存中获取用户信息
            AppUserCacheVO userInfo=userCache.retrieve(token);
            if(null == userInfo){
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            boolean isSuccess = iAppMineServiceClient.deleteAuthPerson(userInfo.getUserId(),authPhoneNo,userInfo.getCurrentProjectId());
            if(!isSuccess){
                return new MessageVO(BaseErrorCodeEnum.ERROR.getErrorCode());
            }
            messageVO = new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode());
        }catch (Exception e){
            throw new DataAccessException("【APP_我的版块】删除授权人失败",e);
        }
        return messageVO;
    }

    /**
     * <desc>
     *      获取用户二维码
     * </desc>
     *
     * @param token 用户token
     * @param projectId 项目id
     * @param createTime 时间戳 验证签名
     * @param sign 签名
     * @return
     * @author Jiaqi.X
     * @createDate 2017/11/15
     */
    @RequestMapping(path = "/getQRcode",method = RequestMethod.POST)
    @ResponseBody
    public Object getQRcode(String token,String roomId,String projectId,String createTime,String sign,String language){
        MessageVO messageVO;
        try {
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                projectId = request.getAttribute("projectId") == null ? null : request.getAttribute("projectId").toString();
                roomId = request.getAttribute("roomId") == null ? null : request.getAttribute("roomId").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            Map<String,String> params = new HashMap<>();
            params.put("projectId",projectId);
            params.put("createTime",createTime);
            params.put("language",language);
            //验证签名
            if (flag1) {
                if(!Md5EncryptUtil.checkAppSign(params, sign, APP_REQUEST_PARAMS_ENCRYPT_KEY)) {
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode():AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }
            } else {
                params.put("roomId",roomId);
                if(!Md5EncryptUtil.checkAppSignValue(params, sign, APP_REQUEST_PARAMS_ENCRYPT_KEY)) {
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode():AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }
            }
            if (StringUtils.isBlank(projectId) || !projectId.matches("[0-9]{8}")) {
                LOG.info("【APP_我的版块】获取用户二维码_项目编号非法】" + projectId);
                ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.PROJECT_NOT_MATCH.getErrorCode():AppErrorCodeEnumEN.PROJECT_NOT_MATCH.getErrorCode();
                return  new MessageVO(errorCode);
            }
            //从缓存中获取用户信息
            AppUserCacheVO userInfo=userCache.retrieve(token);
            //更新用户二维码
            ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.SUCCESS.getErrorCode():BaseErrorCodeEnumEN.SUCCESS.getErrorCode();

            iAppDeviceServiceClient.setUserQrCode(userInfo.getUserId(),projectId,roomId);
            messageVO=new MessageVO(errorCode,iAppMineServiceClient.getUserQrcode(projectId,userInfo.getUserId(),roomId));
        }catch (Exception e){
            throw new DataAccessException("【APP_我的版块】获取用户二维码失败",e);
        }
        return messageVO;
    }

     /**
      * <desc>
      *      修改授权人备注。
      * <desc/>
      *
      * @param  authPhoneNo 被授权人手机号
      * @param  userRemarks 被授权人备注
      * @param  token 凭证
      * @param  sign 签名
      * @return
      * @author shengen.T
      * @createDate 2017/11/15
      */
    @LoggerInfo(operateDesc = LogDescConstant.APP_UPDATE_AUTHPERSON_REMARK)
    @RequestMapping(path ="/authPerson/update",method = RequestMethod.POST)
    @ResponseBody
    public Object updateUserRemarks(String authPhoneNo,String userRemarks,String token,String createTime,String sign,String language){
        MessageVO messageVO;
        try {
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                authPhoneNo = request.getAttribute("authPhoneNo") == null ? null : request.getAttribute("authPhoneNo").toString();
                userRemarks = request.getAttribute("userRemarks") == null ? null : request.getAttribute("userRemarks").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            Map<String,String> params = new HashMap<>();
            params.put("authPhoneNo",authPhoneNo);
            params.put("userRemarks",userRemarks);
            params.put("createTime",createTime);
            params.put("language",language);
            //验证签名
            if (flag1) {
                if(!Md5EncryptUtil.checkAppSign(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    return  new MessageVO(AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode());
                }
            } else {
                if(!Md5EncryptUtil.checkAppSignValue(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    return  new MessageVO(AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode());
                }
            }
            //判断被授权人的手机号
            if(!NumberHandlerUtil.isPhoneNo(authPhoneNo)){
                return new MessageVO(AppErrorCodeEnum.PHONE_NOT_MATCH.getErrorCode());
            }
            //判断被授权用户备注
            if(StringUtils.isBlank(userRemarks)){
                return new MessageVO(AppErrorCodeEnum.USER_REMARKS_EMPTY_ERR.getErrorCode());
            }
            //从缓存中获取用户信息
            AppUserCacheVO userInfo=userCache.retrieve(token);
            if(null == userInfo){
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            //LOG.info("【APP_我的版块】修改备注—项目编号】" +userInfo.getCurrentProjectId());
            Integer count = iAppMineServiceClient.updateUserRemarks(authPhoneNo,userInfo.getCurrentProjectId(), userInfo.getUserId(), userRemarks);
            if(count<1){
                return new MessageVO(BaseErrorCodeEnum.ERROR.getErrorCode());
            }

            AppGetAuthPersonPageDTO pageDTO = new AppGetAuthPersonPageDTO();
            pageDTO.setPageNo("1");
            pageDTO.setPageSize("15");
            pageDTO.setLoginUserId(userInfo.getUserId());
            pageDTO.setProjectId(userInfo.getCurrentProjectId());
            Page<AppMineGetAuthPersonPageVO> PageVOPage =iAppMineServiceClient.getAuthPersonPage(pageDTO);
            if((PageVOPage.getRows()!=null)&&(PageVOPage.getRows().size()>0)){
                for(AppMineGetAuthPersonPageVO itemVO:PageVOPage.getRows()){
                    StringHandlerUtil.formatString(itemVO);
                }
            }
            Map<String,Object> map=new HashMap<>();
            map.put("authorizer",PageVOPage.getRows());
            messageVO = new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),map);
        }catch (Exception e){
            throw new DataAccessException("【APP_我的版块】修改授权人备注失败",e);
        }
        return messageVO;
    }

    /**
     * <desc>
     *      获取当前业主审核通过的房屋列表。
     * <desc/>
     *
     * @param  projectId
     * @param  pageNum
     * @param  token
     * @param  createTime
     * @param  sign
     * @param  language
     * @return
     * @author shengen.T
     * @createDate 2018-03-26
     */
    @RequestMapping(value = "/homeList",method = RequestMethod.POST)
    @ResponseBody
    public Object getPassRoomList(String projectId,String pageNum,String token,String createTime,String sign,String language){
        MessageVO messageVO;
        try {
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                projectId = request.getAttribute("projectId") == null ? null : request.getAttribute("projectId").toString();
                pageNum = request.getAttribute("pageNum") == null ? null : request.getAttribute("pageNum").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            //验签
            Map<String,String> params = new HashMap<>();
            params.put("pageNum",pageNum);
            params.put("projectId",projectId);
            params.put("createTime",createTime);
            params.put("language",language);
            //验证签名
            if (flag1) {
                if(!Md5EncryptUtil.checkAppSign(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    return new MessageVO(AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode());
                }
            } else {
                if(!Md5EncryptUtil.checkAppSignValue(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    return new MessageVO(AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode());
                }
            }
            //判断项目编号
            if(StringUtils.isBlank(projectId)){
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            //判断请求页
            if(StringUtils.isBlank(pageNum)){
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            //从缓存中获取用户信息
            AppUserCacheVO userInfo=(AppUserCacheVO)StringHandlerUtil.formatString(userCache.retrieve(token));
            Page<AppPassRoomListVO> pageVO = iAppMineServiceClient.getPassRoomList(projectId,userInfo.getUserId(),pageNum);
            Map<String,Object> map=new HashMap<>();
            map.put("totalNum",pageVO.getPage().getTotalNumber());
            map.put("data",pageVO.getRows());
            messageVO = new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),map);
        }catch (Exception e){
            throw new DataAccessException("【APP_首页版块】获取审核通过的房间列表",e);
        }
        return messageVO;
    }

    /**
     * <desc>
     *      查询余额
     * <desc/>
     * @param   token 用户接入凭证
     * @return  标准化响应结果
     * @author Juguang.S
     * @createDate 2018/4/23
     */
    @ResponseBody
    @RequestMapping("/getUserBalance")
    public Object getUserBalance(String token, String createTime,String sign,String language) {
        try {
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            //验签
            Map<String,String> params = new HashMap<>();
            params.put("createTime",createTime);
            params.put("language",language);
            if (flag1) {
                if (!Md5EncryptUtil.checkAppSign(params, sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }else if (StringUtils.isBlank(token)||StringUtils.isBlank(createTime)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.NOT_PARAM.getErrorCode(): BaseErrorCodeEnumEN.NOT_PARAM.getErrorCode();
                    return new MessageVO(errorCode);
                }
            } else {
                if (!Md5EncryptUtil.checkAppSignValue(params, sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }else if (StringUtils.isBlank(token)||StringUtils.isBlank(createTime)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.NOT_PARAM.getErrorCode(): BaseErrorCodeEnumEN.NOT_PARAM.getErrorCode();
                    return new MessageVO(errorCode);
                }
            }

            String userId = UserTokenUtil.newAPPTokenDecrypt(token, APP_USER_TOKEN_KEY);

            //LOG.info("======token：" + token + "  对应的userId是：" + userId);
            AppUserAccountBalancePO user = iAccountBalanceServiceClient.getUser(userId);
            if(user == null){
                ErrorCode errorCode = AppErrorCodeEnum.NOTN_EXISTENT_ACCOUNT.getErrorCode();
                return new MessageVO(errorCode);
            }
            BigDecimal balance = iAccountBalanceServiceClient.getBalanceByUserId(userId);
            Map<String,Object> returnData = new HashMap<>();
            returnData.put("balance",balance);

            ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.SUCCESS.getErrorCode(): BaseErrorCodeEnumEN.SUCCESS.getErrorCode();
            return new MessageVO(errorCode,returnData);
        } catch (Exception e) {
            throw new DataAccessException("【演示版App_人脸识别_getBalance】查询余额失败", e);
        }
    }


    /**
     * <desc>
     *      演示人脸识别更新余额
     * <desc/>
     * @param
     * @return  标准化响应结果
     * @author Juguang.S
     * @createDate 2018/4/23
     */
    @ResponseBody
    @RequestMapping("/updateUserBalance")
    public Object updateUserBalance(AppUserAccountBalanceDTO appUserAccountBalanceDTO) {

        boolean flag1 = StringUtils.isNotBlank(appUserAccountBalanceDTO.getToken());
        if (!flag1) {
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            appUserAccountBalanceDTO = HttpProtocolUtil.parseRequestParamToDTO(AppUserAccountBalanceDTO.class, request);
        }
        String faceId = appUserAccountBalanceDTO.getFaceId();
        Integer payType = appUserAccountBalanceDTO.getPayType();
        String num = appUserAccountBalanceDTO.getNum();

        try {
            if(StringUtils.isEmpty(faceId) || StringUtils.isEmpty(payType.toString()) || StringUtils.isEmpty(num)){
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }

            /*if(PayTypeEnum.FACE_PAY.getType() == payType ){
                Integer isFace = iAppRegisterServiceClient.getIsFace(faceId);
                if(isFace == 0 || isFace == null){
                    return new MessageVO(AppErrorCodeEnum.NOT_IS_FACE.getErrorCode());
                }
            }*/

            Map<String, Object> returnMap = iAccountBalanceServiceClient.updateBalance(appUserAccountBalanceDTO);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),returnMap);
        } catch (Exception e) {
            throw new DataAccessException("【演示版App_updateBalance】更新余额失败", e);
        }
    }

    /**
     * <desc>
     *      检测订单状态是否为完成
     * <desc/>
     *
     * @param
     * @return  标准化响应结果
     * @author Jiaqi.X
     * @createDate 2018/04/27
     */
    @ResponseBody
    @RequestMapping("/checkTradeSuccess")
    public Object checkTradeSuccess(String token, String createTime,String sign,String language,String billsId,String tradeId) {
        try {
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                billsId = request.getAttribute("billsId") == null ? null : request.getAttribute("billsId").toString();
                tradeId = request.getAttribute("tradeId") == null ? null : request.getAttribute("tradeId").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            //验签
            Map<String,String> params = new HashMap<>();
            params.put("createTime",createTime);
            params.put("language",language);
            params.put("billsId",billsId);
            params.put("tradeId",tradeId);
            if (flag1) {
                if (!Md5EncryptUtil.checkAppSign(params, sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }else if (StringUtils.isBlank(token)||StringUtils.isBlank(createTime)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.NOT_PARAM.getErrorCode(): BaseErrorCodeEnumEN.NOT_PARAM.getErrorCode();
                    return new MessageVO(errorCode);
                }
            } else {
                if (!Md5EncryptUtil.checkAppSignValue(params, sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }else if (StringUtils.isBlank(token)||StringUtils.isBlank(createTime)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.NOT_PARAM.getErrorCode(): BaseErrorCodeEnumEN.NOT_PARAM.getErrorCode();
                    return new MessageVO(errorCode);
                }
            }
            //从缓存中获取用户信息
            AppUserCacheVO userInfo=userCache.retrieve(token);
            Map<String,Object> map = new HashMap<>();
            if(iAccountBalanceServiceClient.checkTradeSuccess(billsId,userInfo.getUserId(),tradeId)){
                //根据账单ID查询月卡订单的截止时间
                String endTime = iAccountBalanceServiceClient.getMonthCardTime(billsId);
                if(StringUtils.isEmpty(endTime)){
                    map.put("remark","");
                }else{
                    map.put("remark",String.format("%s%s","月卡车辆已续费成功，有效期至",endTime));
                }

                //2代表订单支付成功  1代表支付未成功
                map.put("paymentStatus","2");
                if (iAccountBalanceServiceClient.getBalanceByUserId(userInfo.getUserId())!=null) {
                    map.put("balance",iAccountBalanceServiceClient.getBalanceByUserId(userInfo.getUserId()));
                }else{
                    map.put("balance",0.00);
                }
            }else {
                map.put("paymentStatus","1");
                map.put("balance",0.00);
                map.put("remark","");
            }
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),map);
        } catch (Exception e) {
            throw new DataAccessException("【App_checkTradeSuccess】检测订单状态是否为完成失败", e);
        }
    }

    /**
     * <desc>
     *      百度人脸注册。
     * <desc/>
     *
     * @param appCreateBaiduFaceDTO 人脸注册信息DTO
     * @return
     * @author Qiang.S
     * @createDate 2018/04/25
     */
    @LoggerInfo(operateDesc = LogDescConstant.APP_CREATE_BAIDUFACE)
    @RequestMapping(path ="/createBaiduFace",method = RequestMethod.POST)
    @ResponseBody
    public Object createBaiduFace(AppCreateBaiduFaceDTO appCreateBaiduFaceDTO, String sign) {
        MessageVO messageVO;
        try {
            boolean flag1 = StringUtils.isNotBlank(sign);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                appCreateBaiduFaceDTO = HttpProtocolUtil.parseRequestParamToDTO(AppCreateBaiduFaceDTO.class, request);
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
            }
            //验证签名
            Map<String,String> params = new HashMap<>();
            params.put("createTime",appCreateBaiduFaceDTO.getCreateTime());
            params.put("language",appCreateBaiduFaceDTO.getLanguage());
            params.put("imageType",appCreateBaiduFaceDTO.getImageType());
            params.put("projectId",appCreateBaiduFaceDTO.getProjectId());
            if (flag1) {
                params.put("imageStr",appCreateBaiduFaceDTO.getImageStr());
                if(!Md5EncryptUtil.checkAppSign(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    return  new MessageVO(AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode());
                }
            } else {
                if(!Md5EncryptUtil.checkAppSignValue(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    return  new MessageVO(AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode());
                }
            }
            //判断必要信息是否为空
            if(StringUtils.isEmpty(appCreateBaiduFaceDTO.getToken()) || StringUtils.isEmpty(appCreateBaiduFaceDTO.getProjectId())
                    || StringUtils.isEmpty(appCreateBaiduFaceDTO.getImageStr())){
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            //从缓存中获取用户信息
            AppUserCacheVO userInfo=(AppUserCacheVO)StringHandlerUtil.formatString(userCache.retrieve(appCreateBaiduFaceDTO.getToken()));
            if(null == userInfo){
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            //判断项目是否开启人脸识别,并查询是否有百度库key
            OperateFaceApplyInfoVO operateFaceApplyInfoVO = iOperateFaceApplyServiceClient.getFaceByProjectId(appCreateBaiduFaceDTO.getProjectId());
            if(operateFaceApplyInfoVO == null){
                ErrorCode errorCode = AppErrorCodeEnum.PROJECT_FACE_APPID_INEXISTENCE.getErrorCode();
                return new MessageVO(errorCode);
            }
            AppCreateBaiduFaceVO appCreateBaiduFaceVO = new AppCreateBaiduFaceVO();
            appCreateBaiduFaceVO.setProjectId(appCreateBaiduFaceDTO.getProjectId());
            appCreateBaiduFaceVO.setUserPhone(userInfo.getPhoneNo());
            appCreateBaiduFaceVO.setUid(userInfo.getUserId());
            appCreateBaiduFaceVO.setUserName(userInfo.getUserName());
            appCreateBaiduFaceVO.setUserInfo(userInfo.getUserName());//userInfo使用用户名
            appCreateBaiduFaceVO.setAPP_ID(operateFaceApplyInfoVO.getAppId());
            appCreateBaiduFaceVO.setAPI_KEY(operateFaceApplyInfoVO.getApiKey());
            appCreateBaiduFaceVO.setSECRET_KEY(operateFaceApplyInfoVO.getSecretKey());
            //创建百度人脸信息
            String imageStr = URLDecoder.decode(appCreateBaiduFaceDTO.getImageStr(), "UTF-8");
//            appCreateBaiduFaceVO.setFile(new BASE64Decoder().decodeBuffer(imageStr));
            String uploadFilePath = uploadImageFile(appCreateBaiduFaceDTO.getImageStr(), appCreateBaiduFaceDTO.getImageType(), FileCatalogEnum.BAIDU_FACE_CREATE_FILE);
            appCreateBaiduFaceVO.setImageUrl(uploadFilePath);
            appCreateBaiduFaceVO.setUploadFilePath(uploadFilePath);
            appCreateBaiduFaceVO.setJPushFlag("1");//使用极光推送
            boolean result = iIotBaiduFaceServiceClient.createBaiduFace(appCreateBaiduFaceVO);
            if (!result) {
                return new MessageVO(BaseErrorCodeEnum.ERROR.getErrorCode(),result);
            }
            messageVO = new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),result);
            //查询当前项目信息
            ProjectPO projectPO = iOperateProjectServiceClient.getOneProject(appCreateBaiduFaceDTO.getProjectId());
            // 平板优先离线，则插入同步数据
            if (projectPO.getOnOffLinePadFace() != null) {
                PadFaceSyncDataDTO padFaceSyncDataDTO = new PadFaceSyncDataDTO();
                padFaceSyncDataDTO.setOperateType("1");
                padFaceSyncDataDTO.setAppUserIds(userInfo.getUserId());
                padFaceSyncDataDTO.setProjectId(appCreateBaiduFaceDTO.getProjectId());
                padFaceSyncDataDTO.setStatus("1");
                if(projectPO.getOnOffLinePadFace() == 1){
                    iPadFaceSyncDataServiceClient.userOrFloorSync(padFaceSyncDataDTO);
                }
                iPadFaceSyncDataServiceClient.userOrFloorSyncSmartCard(padFaceSyncDataDTO);
            }
        } catch (Exception e) {
            throw new DataAccessException("【App_cteateBaiduFace】人脸认证申请失败", e);
        }
        return messageVO;
    }

    /**
     * <desc>
     *      百度人脸注册信息查询。
     * <desc/>
     *
     * @param token 登陆token
     * @param projectId 项目ID
     * @return
     * @author Qiang.S
     * @createDate 2018/05/08
     */
    @RequestMapping(path ="/getCreateBaiduFaceInfo",method = RequestMethod.POST)
    @ResponseBody
    public Object getCreateBaiduFaceInfo(String token, String projectId,String createTime,String sign,String language) {
        MessageVO messageVO;
        try {
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                projectId = request.getAttribute("projectId") == null ? null : request.getAttribute("projectId").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            //验签
            Map<String,String> params = new HashMap<>();
            params.put("createTime",createTime);
            params.put("language",language);
            params.put("projectId",projectId);
            if (flag1) {
                if (!Md5EncryptUtil.checkAppSign(params, sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }
                //判断必要信息是否为空
                else if (StringUtils.isBlank(token)||StringUtils.isBlank(createTime)|| StringUtils.isEmpty(projectId) || StringUtils.isEmpty(language)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.NOT_PARAM.getErrorCode(): BaseErrorCodeEnumEN.NOT_PARAM.getErrorCode();
                    return new MessageVO(errorCode);
                }
            } else {
                if (!Md5EncryptUtil.checkAppSignValue(params, sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }
                //判断必要信息是否为空
                else if (StringUtils.isBlank(token)||StringUtils.isBlank(createTime)|| StringUtils.isEmpty(projectId) || StringUtils.isEmpty(language)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.NOT_PARAM.getErrorCode(): BaseErrorCodeEnumEN.NOT_PARAM.getErrorCode();
                    return new MessageVO(errorCode);
                }
            }
            //从缓存中获取用户信息
            if(userCache.retrieve(token)==null){
                return new MessageVO(AppErrorCodeEnum.USER_TOKEN_ERROR.getErrorCode());
            }
            AppUserCacheVO userInfo=(AppUserCacheVO)StringHandlerUtil.formatString(userCache.retrieve(token));
            AppUserFaceVO appUserFaceVO = iAppMineServiceClient.getCreateBaiduFaceInfo(userInfo.getUserId(), projectId);
            if(appUserFaceVO==null){
                appUserFaceVO= new AppUserFaceVO();
                appUserFaceVO.setFaceCreateTime("");
                appUserFaceVO.setFacePicUrl("");
                appUserFaceVO.setIsFace("0");
            }
            messageVO = new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),appUserFaceVO);
        } catch (Exception e) {
            throw new DataAccessException("【App_getCreateBaiduFaceInfo】人脸认证查询失败", e);
        }
        return  messageVO;
    }

    /**
     * <desc>
     *      人脸认证权限验证。
     * <desc/>
     *
     * @param token 登陆token
     * @param projectId 项目ID
     * @return
     * @author Qiang.S
     * @createDate 2018/06/07
     */
    @RequestMapping(path ="/cteateBaiduFaceVerify",method = RequestMethod.POST)
    @ResponseBody
    public Object cteateBaiduFaceVerify(String token, String projectId,String createTime,String sign,String language) {
        MessageVO messageVO;
        try {
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                projectId = request.getAttribute("projectId") == null ? null : request.getAttribute("projectId").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            //验签
            Map<String,String> params = new HashMap<>();
            params.put("createTime",createTime);
            params.put("language",language);
            params.put("projectId",projectId);
            if (flag1) {
                if (!Md5EncryptUtil.checkAppSign(params, sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }
                //判断必要信息是否为空
                else if (StringUtils.isBlank(token)||StringUtils.isBlank(createTime)|| StringUtils.isEmpty(projectId) || StringUtils.isEmpty(language)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.NOT_PARAM.getErrorCode(): BaseErrorCodeEnumEN.NOT_PARAM.getErrorCode();
                    return new MessageVO(errorCode);
                }
            } else {
                if (!Md5EncryptUtil.checkAppSignValue(params, sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode(): AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return new MessageVO(errorCode);
                }
                //判断必要信息是否为空
                else if (StringUtils.isBlank(token)||StringUtils.isBlank(createTime)|| StringUtils.isEmpty(projectId) || StringUtils.isEmpty(language)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.NOT_PARAM.getErrorCode(): BaseErrorCodeEnumEN.NOT_PARAM.getErrorCode();
                    return new MessageVO(errorCode);
                }
            }
            OperateFaceApplyInfoVO operateFaceApplyInfoVO = iOperateFaceApplyServiceClient.getFaceByProjectId(projectId);
            messageVO = new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),operateFaceApplyInfoVO);
        } catch (Exception e) {
            throw new DataAccessException("【App_cteateBaiduFaceVerify】人脸认证权限验证", e);
        }
        return  messageVO;
    }

    /**
     * <desc>
     *      修改用户手机。
     * <desc/>
     *
     * @param  newPhoneNo 新手机号
     * @param  token 凭证
     * @param  sign 签名
     * @return
     * @author Qiang.S
     * @createDate 2018/07/03
     */
    @LoggerInfo(operateDesc = LogDescConstant.APP_UPDATE_AUTHPERSON_PHONE)
    @RequestMapping(path ="/authPerson/updateUserPhone",method = RequestMethod.POST)
    @ResponseBody
    public Object updateUserPhone(String newPhoneNo,String smsCode,String token,String createTime,String sign,String language){
        try {
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                newPhoneNo = request.getAttribute("newPhoneNo") == null ? null : request.getAttribute("newPhoneNo").toString();
                smsCode = request.getAttribute("smsCode") == null ? null : request.getAttribute("smsCode").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            Map<String,String> params = new HashMap<>();
            params.put("newPhoneNo",newPhoneNo);
            params.put("smsCode",smsCode);
            params.put("createTime",createTime);
            params.put("language",language);
            //验证签名
            if (flag1) {
                if(!Md5EncryptUtil.checkAppSign(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    return  new MessageVO(AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode());
                }
            } else {
                if(!Md5EncryptUtil.checkAppSignValue(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    return  new MessageVO(AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode());
                }
            }
            //判断新手机号
            if(!NumberHandlerUtil.isPhoneNo(newPhoneNo)){
                return new MessageVO(AppErrorCodeEnum.VISIT_PHONE_IS_NULL.getErrorCode());
            }
            //验证码
            if(StringUtils.isBlank(smsCode)){
                return new MessageVO(AppErrorCodeEnum.SMSCODE_IS_NULL.getErrorCode());
            }

            String smsCodeCache;
            if (NumberHandlerUtil.isPhoneNo(newPhoneNo)){  //手机号
                smsCodeCache = redisService.get(RedisConstant.REDIS_SMS_CODE+newPhoneNo);
            }else if(StringHandlerUtil.isEmail(newPhoneNo)){  //邮箱
                smsCodeCache = redisService.get(RedisConstant.REDIS_EMAIL_CODE+newPhoneNo);
            }else {//帐号不合法
                ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.NOT_PARAM.getErrorCode():BaseErrorCodeEnumEN.NOT_PARAM.getErrorCode();
                return  new MessageVO(errorCode);
            }
            if (StringUtils.isBlank(smsCodeCache)){//验证码过期
                ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.SMSCODE_EXPIRE.getErrorCode():AppErrorCodeEnumEN.SMSCODE_EXPIRE.getErrorCode();
                return  new MessageVO(errorCode);
            }else if (StringUtils.isNotBlank(smsCodeCache)&&!smsCodeCache.equals(smsCode)){//验证码不正确
                ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.SMSCODE_ERR.getErrorCode():AppErrorCodeEnumEN.SMSCODE_ERR.getErrorCode();
                return  new MessageVO(errorCode);
            }else if (StringUtils.isNotBlank(smsCodeCache)&&smsCodeCache.equals(smsCode)){
                //从缓存中获取用户信息
                AppUserCacheVO userInfo=userCache.retrieve(token);
                if(null == userInfo){
                    return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
                }
                int num = iAppMineServiceClient.updateUserPhone(userInfo.getUserId(),newPhoneNo);
                if (num <= 0) {
                    return new MessageVO(BaseErrorCodeEnum.ERROR.getErrorCode(),num);
                }
                return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),"");
            }
            ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.SMSCODE_ERR.getErrorCode():AppErrorCodeEnumEN.SMSCODE_ERR.getErrorCode();
            return  new MessageVO(errorCode);
        }catch (Exception e){
            throw new DataAccessException("【APP_我的版块】修改手机号失败",e);
        }
    }

    /**
     * <desc>
     *       注销。
     * <desc/>
     *
     * @param  phoneNo 手机号
     * @param  token 凭证
     * @param  sign 签名
     * @return
     * @author Jiaqi.X
     * @createDate 2020/06/01
     */
    @LoggerInfo(operateDesc = LogDescConstant.APP_LOGOFF_PHONE)
    @RequestMapping(path ="/logOffUser",method = RequestMethod.POST)
    @ResponseBody
    public Object logOffUser(String phoneNo,String code,String token,String createTime,String sign,String language){
        try {
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                phoneNo = request.getAttribute("phoneNo") == null ? null : request.getAttribute("phoneNo").toString();
                code = request.getAttribute("code") == null ? null : request.getAttribute("code").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            Map<String,String> params = new HashMap<>();
            params.put("phoneNo",phoneNo);
            params.put("code",code);
            params.put("createTime",createTime);
            params.put("language",language);
            //验证签名
            if (flag1) {
                if(!Md5EncryptUtil.checkAppSign(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    return  new MessageVO(AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode());
                }
            } else {
                if(!Md5EncryptUtil.checkAppSignValue(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    return  new MessageVO(AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode());
                }
            }
            //验证码
            if(StringUtils.isBlank(code)){
                return new MessageVO(AppErrorCodeEnum.SMSCODE_IS_NULL.getErrorCode());
            }

            String smsCodeCache;
            if (NumberHandlerUtil.isPhoneNo(phoneNo)){  //手机号
                smsCodeCache = redisService.get(RedisConstant.REDIS_SMS_CODE+phoneNo);
            }else {//帐号不合法
                ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.NOT_PARAM.getErrorCode():BaseErrorCodeEnumEN.NOT_PARAM.getErrorCode();
                return  new MessageVO(errorCode);
            }
            if (StringUtils.isBlank(smsCodeCache)){//验证码过期
                ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.SMSCODE_EXPIRE.getErrorCode():AppErrorCodeEnumEN.SMSCODE_EXPIRE.getErrorCode();
                return  new MessageVO(errorCode);
            }else if (StringUtils.isNotBlank(smsCodeCache)&&!smsCodeCache.equals(code)){//验证码不正确
                ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.SMSCODE_ERR.getErrorCode():AppErrorCodeEnumEN.SMSCODE_ERR.getErrorCode();
                return  new MessageVO(errorCode);
            }else if (StringUtils.isNotBlank(smsCodeCache)&&smsCodeCache.equals(code)){
                String userId = UserTokenUtil.newAPPTokenDecrypt(token, APP_USER_TOKEN_KEY);
                //注销人脸
                iIotVisitorFaceServiceClient.deleteUserFace(userId);
                iAppMineServiceClient.logOff(userId);
            }
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode());
        }catch (Exception e){
            throw new DataAccessException("【APP_我的版块】注销手机号失败",e);
        }
    }

    /**
     * <desc>
     *      上传图片文件
     * <desc/>
     *
     * @param imageStr 图片二进制
     * @param imageType 图片类型
     * @return
     * @author Qiang.S
     * @createDate 2018-05-07
     */
    private String uploadImageFile(String imageStr,String imageType, FileCatalogEnum fileCatalog){
        try {
            imageStr = URLDecoder.decode(imageStr, "UTF-8");
        }catch (Exception e){
            LOG.info("imageStr URLDecoder失败", e);
            return null;
        }
        byte[] bytes = null;
        try {
            bytes = new BASE64Decoder().decodeBuffer(imageStr);
        } catch (IOException e) {
            LOG.info("BASE64Decoder().decodeBuffer失败,imageStr不合法", e);
            return null;
        }
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
        UploadFileUtil.UploadFile uploadFileUtil = new UploadFileUtil().new UploadFile(
                FILE_FTP_HOST,
                FILE_FTP_USERNAME,
                FILE_FTP_PASSWORD,
                FILE_FTP_PORT,
                byteArrayInputStream,
                imageType,
                FILE_ACCESS_URL,
                fileCatalog.getType()
        );
        try {
            //LOG.info("正在上传图片");
            Map<String, Object> resultMap = UploadFileUtil.uploadFile(uploadFileUtil);
            //LOG.info("图片上传完毕");
            String returnCode = resultMap.get("returnCode").toString();
            if ("true".equals(returnCode)){
                String fileUrl = resultMap.get("accessPath").toString();
                return fileUrl;
            }else {
                LOG.info(String.format("图片上传失败，returnCode: %s",returnCode));
                return null;
            }
        } catch (IOException e) {
            LOG.info("UploadFileUtil.uploadFile失败", e);
            return null;
        }
    }

    /**
     * <desc>
     *      因集成灵云快智需要，需将旧数据用户的SIP账号改为灵云快智的userId，前端移动端无需调此接口
     *      因集成灵云快智需要，需将旧数据用户的SIP账号长度改为31位，并创建及绑定灵云快智用户账号，前端移动端无需调此接口
     *      还需将用户信息推送给所有的云对讲设备
     * <desc/>
     *
     * @return
     * @author Juguang.S
     * @createDate 2018-08-24
     */
    @PostMapping(path = "/updateSipAccount")
    @ResponseBody
    public Object updateSipAccount(){
        try {
            iAppMineServiceClient.updateSipAccount();
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode());
        } catch (Exception e) {
            throw new DataAccessException("【APP_我的版块】修改旧SIP账号长度失败",e);
        }
    }

    /**
     * <desc>
     *      推送开启云对讲服务的项目设备重启指令
     * <desc/>
     *
     * @return
     * @author Juguang.S
     * @createDate 2019-01-03
     */
    @PostMapping(path = "/pushCommand")
    @ResponseBody
    public Object pushCommand(){
        try {
            iAppMineServiceClient.pushCommand();
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode());
        } catch (Exception e) {
            throw new DataAccessException("【APP_我的版块】推送开启云对讲服务的项目设备重启指令",e);
        }
    }

    /**
     * <desc>
     *      因集成灵云快智测试需要，根据userId释放灵云快智账号，前端移动端无需调此接口
     * <desc/>
     *
     * @return
     * @author Juguang.S
     * @createDate 2018-09-11
     */
    @PostMapping(path = "/dropSipAccount")
    @ResponseBody
    public Object dropSipAccount(){
        try {
            iAppMineServiceClient.dropSipAccount();
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode());
        } catch (Exception e) {
            throw new DataAccessException("【APP_我的版块】释放灵云快智账号失败",e);
        }
    }

    /**
     * <desc>
     *      补救批量给旧数据绑定灵云快智账号时遗漏账号的操作
     * <desc/>
     *
     * @param  phoneNum 手机号 如有值则创建此手机号的灵云快智账号，如无值则处理所有遗漏创建灵云快智的情况
     * @return
     * @author Juguang.S
     * @createDate 2018-10-15
     */
    @PostMapping(path = "/remedySipAccount")
    @ResponseBody
    public Object remedySipAccount(String phoneNum){
        try{
            if (StringUtils.isBlank(phoneNum)) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                phoneNum = request.getAttribute("phoneNum") == null ? null : request.getAttribute("phoneNum").toString();
            }
            if(StringUtils.isEmpty(phoneNum)){
                phoneNum = "";
            }
            iAppMineServiceClient.remedySipAccount(phoneNum);
        }catch(Exception e){
            throw new DataAccessException("【APP_我的版块】补救批量给旧数据绑定灵云快智账号时遗漏账号的操作失败",e);
        }
        return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode());
    }

    /**
     * <desc>
     *      获取用户无接触二维码
     * </desc>
     *
     * @param deviceUnique 项目id
     * @param logicalFloor 楼层名称
     * @param createTime 时间戳 验证签名
     * @param sign 签名
     * @return
     * @author Qiang.S
     * @createDate 2017/11/15
     */
    @RequestMapping(path = "/getNoTouchQRCode",method = RequestMethod.POST)
    @ResponseBody
    public Object getNoTouchQRCode(String token,String deviceUnique,String logicalFloor,String createTime,String sign,String language) {
        MessageVO messageVO;
        try {
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                deviceUnique = request.getAttribute("deviceUnique") == null ? null : request.getAttribute("deviceUnique").toString();
                logicalFloor = request.getAttribute("logicalFloor") == null ? null : request.getAttribute("logicalFloor").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            Map<String, String> params = new HashMap<>();
            params.put("deviceUnique", deviceUnique);
            params.put("logicalFloor", logicalFloor);
            params.put("createTime", createTime);
            params.put("language", language);
            //验证签名
            if (!Md5EncryptUtil.checkAppSignValue(params, sign, APP_REQUEST_PARAMS_ENCRYPT_KEY)) {
                ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language) ? AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode() : AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                return new MessageVO(errorCode);
            }
            if (StringUtils.isBlank(deviceUnique) || StringUtils.isBlank(logicalFloor)) {
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            //从缓存中获取用户信息
            AppUserCacheVO userInfo=userCache.retrieve(token);

            String noTouchQRCode = iAppDeviceServiceClient.getNoTouchQRCode(userInfo.getUserId(), deviceUnique, logicalFloor);
            Map<String, String> data = new HashMap<>();
            data.put("endTime", "");
            data.put("endTmeHint", "1");
            data.put("qrcode", noTouchQRCode);
            messageVO = new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(), data);
        } catch (Exception e) {
            throw new DataAccessException("【APP_我的版块】获取用户无接触二维码失败", e);
        }
        return messageVO;
    }

    /**
     * <desc>
     *      获取历史反馈列表
     * </desc>
     *
     * @param
     * @return 历史反馈记录列表
     * @Author Zhu.yj
     * @createDate  2020/11/12
     */
    @RequestMapping(value = "/feedback/historyList", method = RequestMethod.POST)
    public Object getFeedbackList(String token, String projectId, String sign, String createTime, String language, String page){
        try{
            boolean flag = StringUtils.isNotBlank(createTime);
            if (!flag) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                projectId = request.getAttribute("projectId") == null ? null : request.getAttribute("projectId").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
                page = request.getAttribute("page") == null ? null : request.getAttribute("page").toString();
            }
            Map<String, String> params = new HashMap<>();
            params.put("projectId", projectId);
            params.put("page", page);
            params.put("createTime", createTime);
            params.put("language", language);
            if (!Md5EncryptUtil.checkAppSignValue(params, sign, APP_REQUEST_PARAMS_ENCRYPT_KEY)) {
                ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language) ? AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode() : AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                return new MessageVO(errorCode);
            }

            AppUserCacheVO  appUserCacheVO = userCache.retrieve(token);
            List<AppFeedbackInfoVO> feedbackInfoVOS = iAppMineServiceClient.getFeedbackList(appUserCacheVO.getUserId(), projectId, page);
            feedbackInfoVOS.forEach(StringHandlerUtil::formatString);
            System.out.println(feedbackInfoVOS.toString());
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(), feedbackInfoVOS);
        }catch (Exception e){
            throw new DataAccessException("【APP_我的版块】获取历史反馈列表失败", e);
        }
    }

    /**
     * <desc>
     *      获取反馈详情
     * </desc>
     *
     * @param token 登录凭证
     * @param feedbackId 反馈信息id
     * @param sign 签名
     * @return
     * @Author Zhu.yj
     * @createDate  2020/11/12
     */
    @RequestMapping(value = "/feedback/historyDetail", method = RequestMethod.POST)
    public Object getFeedbackDetail(String token, String feedbackId, String sign, String createTime, String language){
        try{
            boolean flag = StringUtils.isNotBlank(createTime);
            if (!flag) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                feedbackId = request.getAttribute("feedbackId") == null ? null : request.getAttribute("feedbackId").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            Map<String, String> params = new HashMap<>();
            params.put("feedbackId", feedbackId);
            params.put("createTime", createTime);
            params.put("language", language);
            if (!Md5EncryptUtil.checkAppSignValue(params, sign, APP_REQUEST_PARAMS_ENCRYPT_KEY)) {
                ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language) ? AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode() : AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                return new MessageVO(errorCode);
            }
            if (StringUtils.isBlank(feedbackId)){
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            AppFeedbackInfoVO feedbackInfoVO = iAppMineServiceClient.getFeedbackDetail(feedbackId);
            StringHandlerUtil.formatString(feedbackInfoVO);
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(), feedbackInfoVO);
        }catch (Exception e){
            throw new DataAccessException("【APP_我的版块】获取反馈详情失败", e);
        }
    }


    /**
     * <desc>
     *      获取访客时间限制信息
     * </desc>
     *
     * @param projectId 项目编号
     * @return
     * @author Juguang.S
     * @createDate 2019/09/15
     */
    @ResponseBody
    @RequestMapping(value = "/getVisitorTimeInfo",method = RequestMethod.POST)
    public Object getVisitorTimeInfo(String projectId){
        try{
            HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
            projectId = request.getAttribute("projectId") == null ? null : request.getAttribute("projectId").toString();
            if(StringUtils.isEmpty(projectId)){
                return new MessageVO(BaseErrorCodeEnum.NOT_PARAM.getErrorCode());
            }
            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(),iPropertyVisitorServiceClient.getVisitorTimeInfo(projectId));
        }catch ( Exception e){
            throw new DataAccessException("【家半径APP_访客管理】获取访客时间限制信息失败",e);
        }
    }

    /**
     * <desc>
     *     访客详情
     * </desc>
     *
     * @param
     * @return
     * @author caoshuai
     * @createDate 2021/1/21 15:47
     */
    @ResponseBody
    @PostMapping("/getVisitorsInfo")
    public Object getVisitorsInfo(String projectId, String token, String sign, String passId, String createTime, String language){
        try {
            boolean flag1 = StringUtils.isNotBlank(projectId) || StringUtils.isNotBlank(token) || StringUtils.isNotBlank(sign);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                projectId = request.getAttribute("projectId") == null ? null : request.getAttribute("projectId").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                passId = request.getAttribute("passId") == null ? null : request.getAttribute("passId").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            //验签
            Map<String, String> params = new HashMap<>();
            params.put("projectId", projectId);
            params.put("passId", passId);
            params.put("createTime", createTime);
            params.put("language", language);


            //验证签名
            if (flag1) {
                if(!Md5EncryptUtil.checkAppSign(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    return  new MessageVO(AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode());
                }
            } else {
                if(!Md5EncryptUtil.checkAppSignValue(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    return  new MessageVO(AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode());
                }
            }
            Map<String, Object> data = iAppDevicePassRecordServiceClient.getVisitorsInfo(passId);

            return new MessageVO(BaseErrorCodeEnum.SUCCESS.getErrorCode(), data);
        } catch (Exception e) {
            throw new DataAccessException("【APP_我的版块】获取访客通行密码邀请记录失败", e);
        }
    }

    /**
     * <desc>
     *      添加访客时在非社区场景下获取业主的地址楼层列表
     * </desc>
     *
     * @param token 用户token
     * @param projectId 项目id
     * @param createTime 时间戳 验证签名
     * @param sign  签名
     * @return
     * @author Juguang.S
     * @createDate 2021/04/25
     */
    @RequestMapping(path = "/authPerson/ownerUserFloorInfo",method = RequestMethod.POST)
    @ResponseBody
    public Object ownerUserFloorInfo(String token,String projectId,String createTime,String owner,String sign,String language){
        MessageVO messageVO;
        try{
            boolean flag1 = StringUtils.isNotBlank(createTime);
            if (!flag1) {
                HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
                token = request.getAttribute("token") == null ? null : request.getAttribute("token").toString();
                projectId = request.getAttribute("projectId") == null ? null : request.getAttribute("projectId").toString();
                owner = request.getAttribute("owner") == null ? null : request.getAttribute("owner").toString();
                createTime = request.getAttribute("createTime") == null ? null : request.getAttribute("createTime").toString();
                sign = request.getAttribute("sign") == null ? null : request.getAttribute("sign").toString();
                language = request.getAttribute("language") == null ? null : request.getAttribute("language").toString();
            }
            Map<String,String> params = new HashMap<>();
            params.put("projectId",projectId);
            params.put("createTime",createTime);
            params.put("owner",owner);
            params.put("language",language);
            //验证签名
            if (flag1) {
                if(!Md5EncryptUtil.checkAppSign(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode():AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return  new MessageVO(errorCode);
                }else if (StringUtils.isBlank(projectId)||StringUtils.isBlank(createTime)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.NOT_PARAM.getErrorCode():BaseErrorCodeEnumEN.NOT_PARAM.getErrorCode();
                    return  new MessageVO(errorCode);
                }else if (!projectId.matches("[0-9]{8}")){
                    LOG.info("【APP_我的版块_查询有权楼栋信息_项目编号非法】"+projectId);
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.PROJECT_NOT_MATCH.getErrorCode():AppErrorCodeEnumEN.PROJECT_NOT_MATCH.getErrorCode();
                    return  new MessageVO(errorCode);
                }
            } else {
                if(!Md5EncryptUtil.checkAppSignValue(params,sign,APP_REQUEST_PARAMS_ENCRYPT_KEY)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.APP_SIGN_ERR.getErrorCode():AppErrorCodeEnumEN.APP_SIGN_ERR.getErrorCode();
                    return  new MessageVO(errorCode);
                }else if (StringUtils.isBlank(projectId)||StringUtils.isBlank(createTime)){
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.NOT_PARAM.getErrorCode():BaseErrorCodeEnumEN.NOT_PARAM.getErrorCode();
                    return  new MessageVO(errorCode);
                }else if (!projectId.matches("[0-9]{8}")){
                    LOG.info("【APP_我的版块_查询有权楼栋信息_项目编号非法】"+projectId);
                    ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?AppErrorCodeEnum.PROJECT_NOT_MATCH.getErrorCode():AppErrorCodeEnumEN.PROJECT_NOT_MATCH.getErrorCode();
                    return  new MessageVO(errorCode);
                }
            }
            //从缓存中获取用户信息
            AppUserCacheVO userInfo=userCache.retrieve(token);

            List<AppRoomAuthVO> list=iAppRoomServiceClient.getOwnerUserFloorInfoByProjectId(userInfo.getUserId(),projectId,owner);
            list.forEach(vo->{
                vo=(AppRoomAuthVO) StringHandlerUtil.formatString(vo);
            });
            Map<String,Object> map=new HashMap<>();
            map.put("roomArr",list);
            ErrorCode errorCode = LanguageTypeEnum.CHINESE.getLanguage().equals(language)?BaseErrorCodeEnum.SUCCESS.getErrorCode():BaseErrorCodeEnumEN.SUCCESS.getErrorCode();
            messageVO = new MessageVO(errorCode,map);
        }catch (Exception e){
            throw new DataAccessException("【APP_我的版块】获取所在对应小区有权限的楼栋等信息失败ownerUserInfo",e);
        }
        return messageVO;
    }
    
}
